Registry / type-stubs / pyre-extensions

pyre-extensions

JSON →
library0.0.32pypypi✓ verified 25d ago

Pyre Extensions is a Python library offering type system extensions designed specifically for use with the Pyre type checker. Currently at version 0.0.32 and classified as 'Alpha' development status, it provides advanced typing constructs like `ParameterSpecification`, `none_throws`, and a type-safe `safe_json` module. Its release cadence is closely tied to the development and releases of the main Pyre type checker.

pip install pyre-extensions
INSTALL
IMPORT
SIG · PYRE-EXTENSIONS
P
pyre-extensions
type-stubspythonv0.0.32
Install
1.7s avg
Import
163ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.32 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.178s · 18.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.148s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ParameterSpecification
from pyre_extensions import ParameterSpecification
none_throws
from pyre_extensions import none_throws
safe_json
from pyre_extensions import safe_json
This imports the module, functions are then accessed via `safe_json.load`, `safe_json.dumps`, etc.

This quickstart demonstrates the use of `ParameterSpecification` for typing decorators that preserve function signatures, and `none_throws` for asserting non-None values. It defines a decorator `unwrap` that extracts the first item from a list returned by a function, raising an error if the list is empty. Note that Pyre would perform static analysis to ensure type safety based on these annotations.

from typing import TypeVar, Callable, List from pyre_extensions import ParameterSpecification, none_throws TParams = ParameterSpecification("TParams") TReturn = TypeVar("TReturn") def unwrap(f: Callable[TParams, List[TReturn]]) -> Callable[TParams, TReturn]: """Example of a decorator using ParameterSpecification.""" def inner(*args: TParams.args, **kwargs: TParams.kwargs) -> TReturn: result = f(*args, **kwargs) # Using none_throws for explicit Optional handling first_item = none_throws(result[0]) if result else None if first_item is None: raise ValueError("List must not be empty for unwrap to extract an item") return first_item return inner @unwrap def get_first_char_list(s: str, upper: bool = False) -> List[str]: chars = [c.upper() for c in s] if upper else list(s) return chars @unwrap def get_empty_list(x: int) -> List[int]: return [] # Example usage print(f"First char (upper): {get_first_char_list('hello', upper=True)}") print(f"First char (lower): {get_first_char_list('world')}") try: get_empty_list(123) except ValueError as e: print(f"Caught expected error for empty list: {e}")
Debug
Known issues
gotchaThe library is in 'Development Status :: 3 - Alpha'. This means the API may not be stable, and breaking changes might occur in future versions.
fix
Monitor releases for breaking changes; pin exact versions in production environments. Consult GitHub for the latest API documentation.
affects: <=0.0.32
gotchaThe `ParameterSpecification` type variable's `args` and `kwargs` properties can only be used together in a function definition as `*args` and `**kwargs` with no other parameters listed.
fix
Ensure `*args: TParams.args, **kwargs: TParams.kwargs` is the exclusive parameter signature when using `ParameterSpecification` in this manner.
affects: All
gotchaThe `none_throws` function explicitly raises an `AssertionError` if `None` is passed to it. This might be unexpected if other exception types (e.g., `ValueError` or `TypeError`) are anticipated for null checks.
fix
Catch `AssertionError` specifically or wrap calls to `none_throws` if a different exception type or custom handling is required.
affects: All
breakingThe `safe_json` module is a type-safe replacement for the built-in `json` module. Unlike the standard `json` module, `safe_json` will raise an exception if the input JSON does not strictly match the expected type, which can break existing code expecting more lenient parsing.
fix
When migrating to `safe_json`, ensure that all JSON input strictly conforms to the expected type annotations, or implement robust error handling for `safe_json`'s exceptions.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyre_extensions'
The 'pyre-extensions' package has not been installed in the Python environment, or the environment is not activated.
fix
pip install pyre-extensions
NameError: name 'ParameterSpecification' is not defined
The 'ParameterSpecification' type was used in code without being explicitly imported from the 'pyre_extensions' library.
fix
from pyre_extensions import ParameterSpecification
ModuleNotFoundError: No module named 'pyre_extensions.safe_json'
Users attempting to use the 'safe_json' module are referencing it with an incorrect submodule name; the correct module is 'type_safe_json'.
fix
from pyre_extensions import type_safe_json
NameError: name 'none_throws' is not defined
The 'none_throws' type alias was used in code without being explicitly imported from the 'pyre_extensions' library.
fix
from pyre_extensions import none_throws
Upgrade
Version history
0.0.32latest on PyPI · released Nov 22, 2024
Audit
Dependencies
pyre-checkrequiredThis library provides extensions specifically for the Pyre type checker and its utility is realized when used in conjunction with 'pyre-check'.
Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
pyre-extensions — pip install pyre-extensions · libregistry