From 2e4d07d37635682b40e92d769cee329133d9b07a Mon Sep 17 00:00:00 2001 From: Erik Gaasedelen Date: Fri, 16 Jan 2026 15:34:33 -0800 Subject: [PATCH 1/2] Fix return type annotation bug for issue 814 --- fasthtml/core.py | 2 +- fasthtml/js.py | 18 +++++++++--------- nbs/api/00_core.ipynb | 9 +++------ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/fasthtml/core.py b/fasthtml/core.py index effd92ca..720f4c20 100644 --- a/fasthtml/core.py +++ b/fasthtml/core.py @@ -445,7 +445,7 @@ def _resp(req, resp, cls=empty, status_code=200): "Create appropriate HTTP response from request and response data" if not resp: resp='' if hasattr(resp, '__response__'): resp = resp.__response__(req) - if cls in (Any,FT): cls=empty + if not (isinstance(cls, type) and issubclass(cls, Response)): cls=empty if isinstance(resp, FileResponse) and not os.path.exists(resp.path): raise HTTPException(404, resp.path) resp,kw = _part_resp(req, resp) if isinstance(resp, Response): return resp diff --git a/fasthtml/js.py b/fasthtml/js.py index 660f2be7..b52a8f7a 100644 --- a/fasthtml/js.py +++ b/fasthtml/js.py @@ -6,32 +6,32 @@ __all__ = ['marked_imp', 'npmcdn', 'light_media', 'dark_media', 'MarkdownJS', 'KatexMarkdownJS', 'HighlightJS', 'SortableJS', 'MermaidJS'] -# %% ../nbs/api/03_js.ipynb #ddc8b61a +# %% ../nbs/api/03_js.ipynb #cd3eb2a3 import re from fastcore.utils import * from fasthtml.components import * from fasthtml.xtend import * -# %% ../nbs/api/03_js.ipynb #4c8d1272 +# %% ../nbs/api/03_js.ipynb #f7792683 def light_media( css: str # CSS to be included in the light media query ): "Render light media for day mode views" return Style('@media (prefers-color-scheme: light) {%s}' %css) -# %% ../nbs/api/03_js.ipynb #26cd2ccc +# %% ../nbs/api/03_js.ipynb #0a2307c3 def dark_media( css: str # CSS to be included in the dark media query ): "Render dark media for night mode views" return Style('@media (prefers-color-scheme: dark) {%s}' %css) -# %% ../nbs/api/03_js.ipynb #c7cd64ef +# %% ../nbs/api/03_js.ipynb #f60ca53b marked_imp = """import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js"; """ npmcdn = 'https://cdn.jsdelivr.net/npm/' -# %% ../nbs/api/03_js.ipynb #857e3fe6 +# %% ../nbs/api/03_js.ipynb #3e318ccd def MarkdownJS( sel='.marked' # CSS selector for markdown elements ): @@ -39,7 +39,7 @@ def MarkdownJS( src = "proc_htmx('%s', e => e.innerHTML = marked.parse(e.textContent));" % sel return Script(marked_imp+src, type='module') -# %% ../nbs/api/03_js.ipynb #fa5b6642 +# %% ../nbs/api/03_js.ipynb #595d4e8f def KatexMarkdownJS( sel='.marked', # CSS selector for markdown elements inline_delim='$', # Delimiter for inline math @@ -54,7 +54,7 @@ def KatexMarkdownJS( css = Link(rel="stylesheet", href=npmcdn+"katex@0.16.11/dist/katex.min.css") return scr,css -# %% ../nbs/api/03_js.ipynb #c8144d89 +# %% ../nbs/api/03_js.ipynb #7a2a45ef def HighlightJS( sel='pre code:not([data-highlighted="yes"])', # CSS selector for code elements. Default is industry standard, be careful before adjusting it langs:str|list|tuple='python', # Language(s) to highlight @@ -77,7 +77,7 @@ def HighlightJS( jsd(*hjc, 'highlightjs-copy.min.css', typ='css'), *langjs, Script(src, type='module')] -# %% ../nbs/api/03_js.ipynb #9004c11b +# %% ../nbs/api/03_js.ipynb #59c00b7d def SortableJS( sel='.sortable', # CSS selector for sortable elements ghost_class='blue-background-class' # When an element is being dragged, this is the class used to distinguish it from the rest @@ -88,7 +88,7 @@ def SortableJS( """ % sel return Script(src, type='module') -# %% ../nbs/api/03_js.ipynb #0e060ddb +# %% ../nbs/api/03_js.ipynb #3518340d def MermaidJS( sel='.language-mermaid', # CSS selector for mermaid elements theme='base', # Mermaid theme to use diff --git a/nbs/api/00_core.ipynb b/nbs/api/00_core.ipynb index af6f3fe6..b1a5bdd9 100644 --- a/nbs/api/00_core.ipynb +++ b/nbs/api/00_core.ipynb @@ -1362,7 +1362,7 @@ " \"Create appropriate HTTP response from request and response data\"\n", " if not resp: resp=''\n", " if hasattr(resp, '__response__'): resp = resp.__response__(req)\n", - " if cls in (Any,FT): cls=empty\n", + " if not (isinstance(cls, type) and issubclass(cls, Response)): cls=empty\n", " if isinstance(resp, FileResponse) and not os.path.exists(resp.path): raise HTTPException(404, resp.path)\n", " resp,kw = _part_resp(req, resp)\n", " if isinstance(resp, Response): return resp\n", @@ -3964,11 +3964,8 @@ } ], "metadata": { - "kernelspec": { - "display_name": "python3", - "language": "python", - "name": "python3" - } + "solveit_dialog_mode": "learning", + "solveit_ver": 2 }, "nbformat": 4, "nbformat_minor": 5 From 3f23fd490582ee515384bf5c985143403d31708f Mon Sep 17 00:00:00 2001 From: Erik Gaasedelen Date: Fri, 16 Jan 2026 15:35:06 -0800 Subject: [PATCH 2/2] clean --- nbs/api/00_core.ipynb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/nbs/api/00_core.ipynb b/nbs/api/00_core.ipynb index b1a5bdd9..4d7f4ba1 100644 --- a/nbs/api/00_core.ipynb +++ b/nbs/api/00_core.ipynb @@ -3963,10 +3963,7 @@ "source": [] } ], - "metadata": { - "solveit_dialog_mode": "learning", - "solveit_ver": 2 - }, + "metadata": {}, "nbformat": 4, "nbformat_minor": 5 }