Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tools/mk_pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,37 @@
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)