Backports python3.10 typing features into python 3.7 and newer.
Project description
sigparse
Backports python3.10 typing features into python 3.7, 3.8, and 3.9.
Example
import sigparse
def func(param_a: list[str], param_b: str | int, param_c: tuple[int | None]):
...
# This returns the same result in python 3.7, 3.8, 3.9, and 3.10!
sigparse.sigparse(func)
Sigparse also supports classes.
import sigparse
class MyClass:
a: list[str]
b: str | int
c: tuple[int | None]
sigparse.classparse(MyClass)
PEP 604
By default PEP 604 (| for unions) is only enabled for sigparse.sigparse
and sigparse.classparse
.
The code for PEP 604 was written by @Endercheif.
To enable globally:
import sigparse
sigparse.global_PEP604()
Notes
Inspect
This module uses inspect behind the scenes. For that reason:
- All annotations are
inspect._empty
when there is no annotation. sigparse.Parameter.default
isinspect._empty
when there is no default value.sigparse.Parameter.kind
isinspect._ParameterKind
.sigparse.ClassVar.default
isinspect._empty
when there is no default value to maintain consistency.
Annotated
typing.Annotated
will always be evaluated with include_extras=True
in python3.9.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sigparse-3.0.0.tar.gz
(5.1 kB
view details)
Built Distribution
File details
Details for the file sigparse-3.0.0.tar.gz
.
File metadata
- Download URL: sigparse-3.0.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.8.16 Linux/5.15.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 608d14fd5ead44d84482f2a1139803a0416157a0bac2fffa12382caac9566680 |
|
MD5 | 19c4c62c96e7a981dcc33eec49ae4330 |
|
BLAKE2b-256 | 1d6633bb71611ce82c5464ec4d741ac5ac8416a2b96e87f88934e06db2525fb4 |
File details
Details for the file sigparse-3.0.0-py3-none-any.whl
.
File metadata
- Download URL: sigparse-3.0.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.8.16 Linux/5.15.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51926c7914e5386d43d9503036c93e698e5a32cb88fc8336d89187739f04ddee |
|
MD5 | 1cf676c5ddacce6a031e8be13df9026b |
|
BLAKE2b-256 | c16b96a46ebb118f19bb5f94e2e5553a3552ed97bd8501f592ff005ce0f3185d |