Skip to content

Commit 2e4d07d

Browse files
committed
Fix return type annotation bug for issue 814
1 parent f43c10a commit 2e4d07d

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

fasthtml/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def _resp(req, resp, cls=empty, status_code=200):
445445
"Create appropriate HTTP response from request and response data"
446446
if not resp: resp=''
447447
if hasattr(resp, '__response__'): resp = resp.__response__(req)
448-
if cls in (Any,FT): cls=empty
448+
if not (isinstance(cls, type) and issubclass(cls, Response)): cls=empty
449449
if isinstance(resp, FileResponse) and not os.path.exists(resp.path): raise HTTPException(404, resp.path)
450450
resp,kw = _part_resp(req, resp)
451451
if isinstance(resp, Response): return resp

fasthtml/js.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@
66
__all__ = ['marked_imp', 'npmcdn', 'light_media', 'dark_media', 'MarkdownJS', 'KatexMarkdownJS', 'HighlightJS', 'SortableJS',
77
'MermaidJS']
88

9-
# %% ../nbs/api/03_js.ipynb #ddc8b61a
9+
# %% ../nbs/api/03_js.ipynb #cd3eb2a3
1010
import re
1111
from fastcore.utils import *
1212
from fasthtml.components import *
1313
from fasthtml.xtend import *
1414

15-
# %% ../nbs/api/03_js.ipynb #4c8d1272
15+
# %% ../nbs/api/03_js.ipynb #f7792683
1616
def light_media(
1717
css: str # CSS to be included in the light media query
1818
):
1919
"Render light media for day mode views"
2020
return Style('@media (prefers-color-scheme: light) {%s}' %css)
2121

22-
# %% ../nbs/api/03_js.ipynb #26cd2ccc
22+
# %% ../nbs/api/03_js.ipynb #0a2307c3
2323
def dark_media(
2424
css: str # CSS to be included in the dark media query
2525
):
2626
"Render dark media for night mode views"
2727
return Style('@media (prefers-color-scheme: dark) {%s}' %css)
2828

29-
# %% ../nbs/api/03_js.ipynb #c7cd64ef
29+
# %% ../nbs/api/03_js.ipynb #f60ca53b
3030
marked_imp = """import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";
3131
"""
3232
npmcdn = 'https://cdn.jsdelivr.net/npm/'
3333

34-
# %% ../nbs/api/03_js.ipynb #857e3fe6
34+
# %% ../nbs/api/03_js.ipynb #3e318ccd
3535
def MarkdownJS(
3636
sel='.marked' # CSS selector for markdown elements
3737
):
3838
"Implements browser-based markdown rendering."
3939
src = "proc_htmx('%s', e => e.innerHTML = marked.parse(e.textContent));" % sel
4040
return Script(marked_imp+src, type='module')
4141

42-
# %% ../nbs/api/03_js.ipynb #fa5b6642
42+
# %% ../nbs/api/03_js.ipynb #595d4e8f
4343
def KatexMarkdownJS(
4444
sel='.marked', # CSS selector for markdown elements
4545
inline_delim='$', # Delimiter for inline math
@@ -54,7 +54,7 @@ def KatexMarkdownJS(
5454
css = Link(rel="stylesheet", href=npmcdn+"[email protected]/dist/katex.min.css")
5555
return scr,css
5656

57-
# %% ../nbs/api/03_js.ipynb #c8144d89
57+
# %% ../nbs/api/03_js.ipynb #7a2a45ef
5858
def HighlightJS(
5959
sel='pre code:not([data-highlighted="yes"])', # CSS selector for code elements. Default is industry standard, be careful before adjusting it
6060
langs:str|list|tuple='python', # Language(s) to highlight
@@ -77,7 +77,7 @@ def HighlightJS(
7777
jsd(*hjc, 'highlightjs-copy.min.css', typ='css'),
7878
*langjs, Script(src, type='module')]
7979

80-
# %% ../nbs/api/03_js.ipynb #9004c11b
80+
# %% ../nbs/api/03_js.ipynb #59c00b7d
8181
def SortableJS(
8282
sel='.sortable', # CSS selector for sortable elements
8383
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(
8888
""" % sel
8989
return Script(src, type='module')
9090

91-
# %% ../nbs/api/03_js.ipynb #0e060ddb
91+
# %% ../nbs/api/03_js.ipynb #3518340d
9292
def MermaidJS(
9393
sel='.language-mermaid', # CSS selector for mermaid elements
9494
theme='base', # Mermaid theme to use

nbs/api/00_core.ipynb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@
13621362
" \"Create appropriate HTTP response from request and response data\"\n",
13631363
" if not resp: resp=''\n",
13641364
" if hasattr(resp, '__response__'): resp = resp.__response__(req)\n",
1365-
" if cls in (Any,FT): cls=empty\n",
1365+
" if not (isinstance(cls, type) and issubclass(cls, Response)): cls=empty\n",
13661366
" if isinstance(resp, FileResponse) and not os.path.exists(resp.path): raise HTTPException(404, resp.path)\n",
13671367
" resp,kw = _part_resp(req, resp)\n",
13681368
" if isinstance(resp, Response): return resp\n",
@@ -3964,11 +3964,8 @@
39643964
}
39653965
],
39663966
"metadata": {
3967-
"kernelspec": {
3968-
"display_name": "python3",
3969-
"language": "python",
3970-
"name": "python3"
3971-
}
3967+
"solveit_dialog_mode": "learning",
3968+
"solveit_ver": 2
39723969
},
39733970
"nbformat": 4,
39743971
"nbformat_minor": 5

0 commit comments

Comments
 (0)