Skip to main content

Backports Python Typing Stubs

Project description

unpy

Backports Python typing stubs to earlier Python versions

unpy - PyPI unpy - Python Versions unpy - license

unpy - CI unpy - pre-commit unpy - basedpyright unpy - ruff


[!IMPORTANT] This project is in the early stages of development; You probably shouldn't use it in production.

Installation

The unpy package is available as on PyPI, and can be installed with e.g.

pip install unpy

Usage

$ unpy --help
Usage: unpy [OPTIONS] SOURCE [OUTPUT]

Arguments:
  SOURCE    Path to the input .pyi file or '-' to read from stdin.  [required]
  [OUTPUT]  Path to the output .pyi file. Defaults to stdout.

Options:
  -V, --version        Show the version and exit
  -P, --python [3.11]  The minimum Python version that should be supported.
                       [default: 3.11]
  --help               Show this message and exit.

Features

  • Python 3.13 => 3.12
    • PEP 742: typing.TypeIs => typing_extensions.TypeIs
    • PEP 705: typing.ReadOnly => typing_extensions.ReadOnly
    • PEP 702: warnings.deprecated => typing_extensions.deprecated
    • PEP 696: Backport PEP 695 type signatures i.f.f. it includes a type parameter with default
    • PEP 696: typing.NoDefault => typing_extensions.NoDefault
    • typing.get_protocol_members => typing_extensions.get_protocol_members
    • typing.is_protocol => typing_extensions.is_protocol
    • typing.is_protocol => typing_extensions.is_protocol
    • types.CapsuleType => typing_extensions.CapsuleType
    • nested typing.Final and typing.ClassVar
  • Python 3.12 => 3.11
    • PEP 698: typing.override => typing_extensions.override
    • PEP 695: Backport generic functions
    • PEP 695: Backport generic classes
    • PEP 695: Backport generic protocols
    • PEP 695: type {} = ... => {}: TypeAlias = ... or
    • PEP 695: typing.TypeAliasType => typing_extensions.TypeAliasType
    • PEP 688: collections.abc.Buffer => typing_extensions.Buffer
    • PEP 688: inspect.BufferFlags => int
    • Backport subclasses of path.Path
  • Python 3.11 => 3.10
    • PEP 681: typing.dataclass_transform => typing_extensions.dataclass_transform
    • PEP 680: tomllib => tomli
    • PEP 675: typing.LiteralString => typing_extensions.LiteralString
    • PEP 673: typing.Self => typing_extensions.Self
    • PEP 655: typing.[Not]Required => typing_extensions.[Not]Required
    • PEP 646: *Ts => typing_extensions.Unpack[Ts]
  • Generated TypeVars
    • Prefix extracted TypeVars names with _
    • De-duplicate extracted TypeVars
    • Prevent TypeVar name clashes (rename or merge)
    • Infer variance of typing_extensions.TypeVar(..., infer_variance=True) whose name does not end with _contra/_in (contravariant=True) or _co/_out (covariant=True)
    • Convert default=Any to default={bound} or default=object
    • Remove bound=Any and bound=object
    • Importing TypeVar's (not recommended)
  • Imports
    • Reuse existing from typing[_extensions] import {name} imports instead of adding new ones
    • Reuse from {module} import {name} as {alias} import aliases if present, e.g. from typing import TypeVar as TypeParam
    • Reuse import {module} as {alias} if present, e.g. import typing as tp
    • Support for custom typing modules (like [tool.ruff.lint.typing-modules])
    • Support for from typing[_extensions] import * (not recommended)
  • Interface
    • Backport from stdin / to stdout
    • Backport a single .pyi file
    • Backport all .pyi files in package
    • Configuration options in pyproject.toml as [tools.unpy]
    • Project build tools
    • Configurable type-checker integration
    • Configurable post processing with e.g. ruff format
  • Integration
    • File watcher
    • Pre-commit
    • VSCode extension
    • (based)mypy plugin
  • Misc
    • .py support
    • Transform self parameters to be positional-only
    • Use None as the default return type
    • De-duplicate and flatten unions and literals
    • type[S] | type[T] => type[S | T]
  • Extended syntax
    • Write _: True | 1 | "a" instead of _: Literal[True, 1, "a"]
    • Allow omitting @overload
    • Intersection types
    • Mapped types
    • Higher-kinded types

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

unpy-0.2.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

unpy-0.2.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file unpy-0.2.1.tar.gz.

File metadata

  • Download URL: unpy-0.2.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for unpy-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c5caea87577f2e87044063951d3c3b5a85f7b2c166a4c26e86b7f3ea6615b614
MD5 ee6159869abecdcda915b78d27c83957
BLAKE2b-256 4a760764472b2238f84727adc82904b6e58a814e5936df6357dfe39430bcc186

See more details on using hashes here.

File details

Details for the file unpy-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: unpy-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for unpy-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c6eb88dc38265c9c4191c04486003e911a99b3e90b0f48e12850e6958569e67
MD5 822da813234f8c80ccd6d1c2414a2d13
BLAKE2b-256 4c52add7c66cb066881875d24895bacb06713f1540dc45932e73e672a938ae53

See more details on using hashes here.

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