Utilities for inspecting and comparing Python function signatures.
Project description
Signatures
Utitilties for assessing Python function signature equality and compatibility, with the latter accounting for subtypes (including Generics!)
Examples
See the test suite for a full set of examples.
Equality
# Identical function signatures are equal.
import signatures
def foo(thing: Any) -> None:
pass
def bar(thing: Any) -> None:
pass
assert signatures.equal(foo, bar)
# Different function signatures are not equal.
import signatures
def foo(eggs: Any) -> None:
pass
def bar(cheese: Any) -> None:
pass
assert not signatures.equal(foo, bar)
Compatibility
# A function signature is compatible with a more
# generic function signature.
from typing import TypeVar
import signatures
T = TypeVar("T", bound=int)
def foo(thing: bool) -> None:
pass
def bar(thing: T) -> None:
pass
assert signatures.compatible(foo, bar)
# Compatibility checks support nested Generic types.
import signatures
def foo(thing: List[Tuple[bool, str]]) -> None:
pass
def bar(thing: List[Tuple[int, str]]) -> None:
pass
assert signatures.compatible(foo, bar)
# A function signature is not compatible when
# Generic types are not compatible.
import signatures
def foo(thing: List[int]) -> None:
pass
def bar(thing: List[Tuple[int, str]]) -> None:
pass
assert not signatures.compatible(foo, bar)
License
Mozilla Public License v2.0
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
signatures-0.3.1.tar.gz
(8.4 kB
view details)
Built Distribution
File details
Details for the file signatures-0.3.1.tar.gz
.
File metadata
- Download URL: signatures-0.3.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.2 Linux/5.13.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88c1fb6f176eebc9f8493993214f573785fc72fb107ec989cdf9b306ddc9a3bd |
|
MD5 | c10ddaa2b3b0f9080bde15419f3704c2 |
|
BLAKE2b-256 | 9f69ae943b31e5876a12b38151d5b3527518a7470e43b3593c14be1e01db14fa |
File details
Details for the file signatures-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: signatures-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.2 Linux/5.13.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d3c3850b81b2d5e22536dbdc8d22ba9dd1b51434244bb1d9a64325f4732cb58 |
|
MD5 | 55e4c49744b8f08ed258e164660c5eb5 |
|
BLAKE2b-256 | e8acf0c638f14901afe5f27aea790d5005c54a13c81289c4d5d49718d19f4de8 |