Skip to main content

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 is inspect._empty when there is no default value.
  • sigparse.Parameter.kind is inspect._ParameterKind.
  • sigparse.ClassVar.default is inspect._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


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 hashes)

Uploaded Source

Built Distribution

sigparse-3.0.0-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page