python-annotated-types
Port variant v13
Summary Reusable constraint types (3.13)
BROKEN
Package version 0.7.0
Homepage https://github.com/annotated-types/annotated-types
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants v12
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 11 NOV 2024, 23:28:05 UTC
Port created 05 MAR 2024, 06:30:48 UTC
Subpackage Descriptions
single # annotated-types [CI] [pypi] [versions] [license] [PEP-593] added `typing.Annotated` as a way of adding context-specific metadata to existing types, and specifies that `Annotated[T, x]` _should_ be treated as `T` by any tool or library without special logic for `x`. This package provides metadata objects which can be used to represent common constraints such as upper and lower bounds on scalar values and collection sizes, a `Predicate` marker for runtime checks, and descriptions of how we intend these metadata to be interpreted. In some cases, we also note alternative representations which do not require this package. ## Install ```bash pip install annotated-types ``` ## Examples ```python from typing import Annotated from annotated_types import Gt, Len, Predicate class MyClass: age: Annotated[int, Gt(18)] # Valid: 19, 20, ... # Invalid: 17, 18, "19", 19.0, ... factors: list[Annotated[int, Predicate(is_prime)]] # Valid: 2, 3, 5, 7, 11, ... # Invalid: 4, 8, -2, 5.0, "prime", ... my_list: Annotated[list[int], Len(0, 10)] # Valid: [], [10, 20, 30, 40, 50] # Invalid: (1, 2), ["abc"], [0] * 20 ``` ## Documentation _While `annotated-types` avoids runtime checks for performance, users should not construct invalid combinations such as `MultipleOf("non-numeric")` or `Annotated[int, Len(3)]`. Downstream implementors may choose to raise an error, emit a warning, silently ignore a metadata item, etc., if the metadata objects described below are used with an incompatible type - or for any other reason!_ ### Gt, Ge, Lt, Le Express inclusive and/or exclusive bounds on orderable values - which may be numbers, dates, times, strings, sets, etc. Note that the boundary value need not be of the same type that was annotated, so long as they can be compared: `Annotated[int, Gt(1.5)]` is fine, for example, and implies that the value is an integer x such that `x > 1.5`. We suggest that implementors may also interpret `functools.partial(operator.le, 1.5)` as being equivalent to `Gt(1.5)`, for users who wish to avoid a runtime dependency on the `annotated-types` package. To be explicit, these types have the following meanings: * `Gt(x)` - value must be "Greater Than" `x` - equivalent to exclusive minimum * `Ge(x)` - value must be "Greater than or Equal" to `x` - equivalent to inclusive minimum * `Lt(x)` - value must be "Less Than" `x` - equivalent to exclusive maximum * `Le(x)` - value must be "Less than or Equal" to `x` - equivalent to inclusive maximum ### Interval `Interval(gt, ge, lt, le)` allows you to specify an upper and lower bound with a single metadata object. `None` attributes should be ignored, and non-`None` attributes treated as per the single bounds above. ### MultipleOf `MultipleOf(multiple_of=x)` might be interpreted in two ways:
Configuration Switches (platform-specific settings discarded)
PY312 OFF Build using Python 3.12 PY313 ON Build using Python 3.13
Package Dependencies by Type
Build (only) python313:dev:std
python-pip:single:v13
autoselect-python:single:std
Build and Runtime python313:primary:std
Download groups
main mirror://PYPIWHL/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8
Distribution File Information
1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53 13643 annotated_types-0.7.0-py3-none-any.whl
Ports that require python-annotated-types:v13
python-pydantic:v13 Data validation using Python type hints (3.13)