Add your description here
Project description
Dyntypes
Dyntypes is a library for generatinging
from dyntypes import Codegen
import typing as t
codegen = Codegen()
query_func = codegen.func()
@query_func.bind
def query(statement: str, args: tuple) -> tuple: ...
def generate_types():
query_func.overload(
filename="SELECT * FROM posts WHERE ID = ",
args=tuple[int],
return_type=list[str | int],
)
query_func.overload(filename=str, return_type=t.Never)
codegen.save()
if __name__ == "__main__":
generate_types()
What are Type Stubs?
Type stubs are a way of adding type hints to files in python, intended for C extensions.
However, there is nothing stopping code from using this to annotate dynamic types on files.
Quickstart Guide
Create a codegen object, this stores all the type information you'll bind to functions
from dyntypes import Codegen
codegen = Codegen()
Create a function type object
example_func = codegen.func()
@example_func.bind
def example(bar: str) -> int | None: ...
Next we apply overloads to this function, we use the function binding to do this.
I recommend creating a seperate function for type generation so that it can be run conditionally.
def generate_types():
query_func.overload(
filename="SELECT * FROM posts WHERE ID = ",
args=tuple[int],
return_type=list[str | int],
)
query_func.overload(filename=str, return_type=t.Never)
codegen.generate() # Writes out the type stub files
Examples
For example implementations, see the examples folder at LINK HEERE
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dyntypes-0.1.0.tar.gz.
File metadata
- Download URL: dyntypes-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8acf5b45c013378b54b9d74972a91ea6d0bd5dc0544305a92243b20bd3bf4ae
|
|
| MD5 |
ebfe49b9cbc22f4849ccd95e1eebc683
|
|
| BLAKE2b-256 |
bf81b506071540837e9f5dc37602d61a5f76fadd8d0186964f55960299f50927
|
File details
Details for the file dyntypes-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dyntypes-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1874e7600864c064809a9437955ae96e2462680bec2553cfe5b664b44eef09c6
|
|
| MD5 |
5c31f3fa46d7b73f85038ea15017bf63
|
|
| BLAKE2b-256 |
ce61a804f3095112df5490dfd7984ed01a5a0d503c604903a26c3f7cd80c9033
|