Type system extensions for use with the pyre type checker
Project description
Pyre Extensions
This module defines extensions to the standard “typing” module that are supported by the Pyre typechecker.
none_throws
Function to make assumptions about Optional
s explicit. The function will raise an
assertion error if passed None
and return the value otherwise.
ParameterSpecification
ParameterSpecification
s are a special kind of type variable that captures callable parameter
specifications (known as argspecs in the runtime and inspect library) instead of types, allowing
the typing of decorators which transform the return type of the given callable.
For example:
from typing import TypeVar, Callable, List
from pyre_extensions import ParameterSpecification
Tparams = ParameterSpecification("Tparams")
Treturn = TypeVar("Treturn")
def unwrap(f: Callable[Tparams, List[Treturn]) -> Callable[Tparams, Treturn]:
def inner(*args: TParams.args, **kwargs: TParams.kwargs):
return f(*args, **kwargs)[0]
return inner
@unwrap
def foo(x: int, y: str, z: bool = False) -> List[int]:
return [1, 2, 3]
decorates foo into a callable that returns int, but still has the same parameters, including their names and whether they are required.
These ParameterSpecification
variables also have two special properties, args
and kwargs
,
which correspond to the positional and keyword arguments for a specific call to the
ParameterSpecification
function. Because the division of parameters into these two argument
collections can be different each invocation, these special annotations can only be used in one
manner: together, in a function definition, as *args
and **kwargs
with no other parameters
listed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyre_extensions-0.0.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ca81b464003316f9c2f20702410558f7872132bc7a8f870b23be17cbdd11e8c |
|
MD5 | 7648d8a8ecf6f4dfd1e65d7ef9a028b9 |
|
BLAKE2b-256 | a28d33cacc158b91ae86ea66b20f23674cd4e620324083ee7695373cf8cd8816 |