From 6bdff743fadb4624af9d58bf52ce600118ee2ec6 Mon Sep 17 00:00:00 2001 From: Steve Liu Date: Wed, 9 Jul 2025 09:50:02 +0800 Subject: [PATCH 1/5] Add method signatures to request methods To let Pylance stop warning me that these methods doesn't exist. --- fasthtml/core.pyi | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/fasthtml/core.pyi b/fasthtml/core.pyi index 1db52487..864f9a02 100644 --- a/fasthtml/core.pyi +++ b/fasthtml/core.pyi @@ -281,6 +281,23 @@ class FastHTML(Starlette): def devtools_json(self, path=None, uuid=None): ... + + def get(self, path:str): + ... + def post(self, path:str): + ... + def put(self, path:str): + ... + def delete(self, path:str): + ... + def patch(self, path:str): + ... + def head(self, path:str): + ... + def trace(self, path:str): + ... + def options(self, path:str): + ... all_meths = 'get post put delete patch head trace options'.split() def _mk_locfunc(f, p): @@ -376,4 +393,4 @@ def unqid(seeded=False): def _add_ids(s): ... -devtools_loc = '/.well-known/appspecific/com.chrome.devtools.json' \ No newline at end of file +devtools_loc = '/.well-known/appspecific/com.chrome.devtools.json' From 7fd80c5cd7cd87d8c748bddaa77030f6e60eeead Mon Sep 17 00:00:00 2001 From: Steve Liu Date: Fri, 12 Sep 2025 22:35:12 +0800 Subject: [PATCH 2/5] Undo the previous change --- fasthtml/core.pyi | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/fasthtml/core.pyi b/fasthtml/core.pyi index 864f9a02..b72aa1a3 100644 --- a/fasthtml/core.pyi +++ b/fasthtml/core.pyi @@ -281,23 +281,6 @@ class FastHTML(Starlette): def devtools_json(self, path=None, uuid=None): ... - - def get(self, path:str): - ... - def post(self, path:str): - ... - def put(self, path:str): - ... - def delete(self, path:str): - ... - def patch(self, path:str): - ... - def head(self, path:str): - ... - def trace(self, path:str): - ... - def options(self, path:str): - ... all_meths = 'get post put delete patch head trace options'.split() def _mk_locfunc(f, p): From 0bef3f576c8d1bed8eff1b102ab8c84aca7f9929 Mon Sep 17 00:00:00 2001 From: Steve Liu Date: Fri, 12 Sep 2025 23:37:05 +0800 Subject: [PATCH 3/5] Undo last change --- fasthtml/core.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fasthtml/core.pyi b/fasthtml/core.pyi index b72aa1a3..1db52487 100644 --- a/fasthtml/core.pyi +++ b/fasthtml/core.pyi @@ -376,4 +376,4 @@ def unqid(seeded=False): def _add_ids(s): ... -devtools_loc = '/.well-known/appspecific/com.chrome.devtools.json' +devtools_loc = '/.well-known/appspecific/com.chrome.devtools.json' \ No newline at end of file From 74c0a63c1f4c7dd31e2e3a93cee2b91478655d8c Mon Sep 17 00:00:00 2001 From: Steve Liu Date: Sat, 13 Sep 2025 16:03:37 +0000 Subject: [PATCH 4/5] feat(mk_pyi): add type stubs for request methods in core.pyi To avoid method not found error by Pylance due to dynamicly generated methods. --- tools/mk_pyi.py | 56 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/tools/mk_pyi.py b/tools/mk_pyi.py index 76849232..d8e05d1a 100755 --- a/tools/mk_pyi.py +++ b/tools/mk_pyi.py @@ -3,14 +3,48 @@ from fasthtml.components import _all_, hx_attrs_annotations from fastcore.py2pyi import create_pyi -create_pyi('fasthtml/core.py', 'fasthtml') -create_pyi('fasthtml/components.py', 'fasthtml') -create_pyi('fasthtml/xtend.py', 'fasthtml') -with open('fasthtml/components.pyi', 'a') as f: - attrs_str = ', '.join(f'{t}:Any=None' for t in hx_attrs) - f.write(f"\ndef ft_html(tag: str, *c, {attrs_str}, **kwargs): ...\n") - f.write(f"def ft_hx(tag: str, *c, {attrs_str}, **kwargs): ...\n") - for o in _all_: - attrs = (['name'] if o.lower() in named else []) + hx_attrs + evt_attrs - attrs_str = ', '.join(f'{t}:{"Any" if t not in hx_attrs_annotations else str(hx_attrs_annotations[t]).replace("typing.","")}=None' for t in attrs) - f.write(f"def {o}(*c, {attrs_str}, **kwargs): ...\n") +#create_pyi('fasthtml/core.py', 'fasthtml') +#create_pyi('fasthtml/components.py', 'fasthtml') +#create_pyi('fasthtml/xtend.py', 'fasthtml') +#with open('fasthtml/components.pyi', 'a') as f: +# attrs_str = ', '.join(f'{t}:Any=None' for t in hx_attrs) +# f.write(f"\ndef ft_html(tag: str, *c, {attrs_str}, **kwargs): ...\n") +# f.write(f"def ft_hx(tag: str, *c, {attrs_str}, **kwargs): ...\n") +# for o in _all_: +# attrs = (['name'] if o.lower() in named else []) + hx_attrs + evt_attrs +# attrs_str = ', '.join(f'{t}:{"Any" if t not in hx_attrs_annotations else str(hx_attrs_annotations[t]).replace("typing.","")}=None' for t in attrs) +# f.write(f"def {o}(*c, {attrs_str}, **kwargs): ...\n") + +with open('fasthtml/core.pyi', 'r+') as f: + methods = """ + def get(self, path:str): + ... + + def post(self, path:str): + ... + + def put(self, path:str): + ... + + def delete(self, path:str): + ... + + def patch(self, path:str): + ... + + def head(self, path:str): + ... + + def options(self, path:str): + ... + + def trace(self, path:str): + ...\n""" + + lines = f.readlines() + for i, line in enumerate(lines): + if line.startswith('all_meths = '): # Add type stubs of request methods before defination of `all_meths`. + lines.insert(i, methods) + break + f.seek(0) + f.writelines(lines) From c3c4594ff51e2e157e3ffdcb4da2f639a3bfc6b2 Mon Sep 17 00:00:00 2001 From: Steve Liu Date: Sat, 13 Sep 2025 16:27:22 +0000 Subject: [PATCH 5/5] fix(mk_pyi): wrong sharp in mk_pyi.py L6-16 --- tools/mk_pyi.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/mk_pyi.py b/tools/mk_pyi.py index d8e05d1a..2af99b3f 100755 --- a/tools/mk_pyi.py +++ b/tools/mk_pyi.py @@ -3,17 +3,17 @@ from fasthtml.components import _all_, hx_attrs_annotations from fastcore.py2pyi import create_pyi -#create_pyi('fasthtml/core.py', 'fasthtml') -#create_pyi('fasthtml/components.py', 'fasthtml') -#create_pyi('fasthtml/xtend.py', 'fasthtml') -#with open('fasthtml/components.pyi', 'a') as f: -# attrs_str = ', '.join(f'{t}:Any=None' for t in hx_attrs) -# f.write(f"\ndef ft_html(tag: str, *c, {attrs_str}, **kwargs): ...\n") -# f.write(f"def ft_hx(tag: str, *c, {attrs_str}, **kwargs): ...\n") -# for o in _all_: -# attrs = (['name'] if o.lower() in named else []) + hx_attrs + evt_attrs -# attrs_str = ', '.join(f'{t}:{"Any" if t not in hx_attrs_annotations else str(hx_attrs_annotations[t]).replace("typing.","")}=None' for t in attrs) -# f.write(f"def {o}(*c, {attrs_str}, **kwargs): ...\n") +create_pyi('fasthtml/core.py', 'fasthtml') +create_pyi('fasthtml/components.py', 'fasthtml') +create_pyi('fasthtml/xtend.py', 'fasthtml') +with open('fasthtml/components.pyi', 'a') as f: + attrs_str = ', '.join(f'{t}:Any=None' for t in hx_attrs) + f.write(f"\ndef ft_html(tag: str, *c, {attrs_str}, **kwargs): ...\n") + f.write(f"def ft_hx(tag: str, *c, {attrs_str}, **kwargs): ...\n") + for o in _all_: + attrs = (['name'] if o.lower() in named else []) + hx_attrs + evt_attrs + attrs_str = ', '.join(f'{t}:{"Any" if t not in hx_attrs_annotations else str(hx_attrs_annotations[t]).replace("typing.","")}=None' for t in attrs) + f.write(f"def {o}(*c, {attrs_str}, **kwargs): ...\n") with open('fasthtml/core.pyi', 'r+') as f: methods = """