-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add annotations and py.typed to conform with PEP561. Add type checkin…
…g to tox (#40) * Add type stubs and py.typed. Add type checking to tox * use black on pyi * Fix type packagings Signed-off-by: Wilfred Wong <keiclone@users.noreply.github.com> Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> Co-authored-by: Bernat Gabor <bgabor8@bloomberg.net>
- Loading branch information
1 parent
ae8e8d0
commit 79bfc60
Showing
13 changed files
with
218 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from ._error import ( | ||
AttributeTypeError as AttributeTypeError, | ||
BadTypeError as BadTypeError, | ||
TupleError as TupleError, | ||
TypeValidationError as TypeValidationError, | ||
UnionError as UnionError, | ||
) | ||
from ._type_validation import type_validator as type_validator |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import typing | ||
|
||
def is_newtype(type_: typing.Type[typing.Any]) -> bool: ... | ||
def format_type(type_: typing.Type[typing.Any]) -> str: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import typing | ||
import attr | ||
import inspect | ||
|
||
class TypeValidationError(Exception): | ||
def __repr__(self) -> str: ... | ||
|
||
class BadTypeError(TypeValidationError, ValueError): | ||
def __init__(self) -> None: | ||
self.containers: typing.List[typing.Iterable[typing.Any]] | ||
def add_container(self, container: typing.Any) -> None: ... | ||
def _render(self, error: str) -> str: ... | ||
|
||
class AttributeTypeError(BadTypeError): | ||
def __init__( | ||
self, value: typing.Any, attribute: attr.Attribute[typing.Any] | ||
) -> None: ... | ||
def __str__(self) -> str: ... | ||
|
||
class CallableError(BadTypeError): | ||
def __init__( | ||
self, | ||
attribute: attr.Attribute[typing.Any], | ||
callable_signature: inspect.Signature, | ||
expected_signature: typing.Type[typing.Callable[..., typing.Any]], | ||
mismatch_callable_arg: inspect.Parameter, | ||
expected_callable_arg: inspect.Parameter, | ||
) -> None: ... | ||
def __str__(self) -> str: ... | ||
|
||
class EmptyError(BadTypeError): | ||
def __init__( | ||
self, container: typing.Any, attribute: attr.Attribute[typing.Any] | ||
) -> None: ... | ||
def __str__(self) -> str: ... | ||
|
||
class TupleError(BadTypeError): | ||
def __init__( | ||
self, | ||
container: typing.Any, | ||
attribute: typing.Optional[typing.Type[typing.Any]], | ||
tuple_types: typing.Tuple[typing.Type[typing.Any]], | ||
) -> None: ... | ||
def __str__(self) -> str: ... | ||
def _more_or_less(self) -> str: ... | ||
|
||
class UnionError(BadTypeError): | ||
def __init__( | ||
self, | ||
container: typing.Any, | ||
attribute: str, | ||
expected_type: typing.Type[typing.Any], | ||
) -> None: ... | ||
def __str__(self) -> str: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import typing | ||
import attr | ||
|
||
def type_validator( | ||
empty_ok: bool = True, | ||
) -> typing.Callable[ | ||
[typing.Any, attr.Attribute[typing.Any], typing.Any], None | ||
]: | ||
def _validator( | ||
instance: typing.Any, | ||
attribute: attr.Attribute[typing.Any], | ||
field: typing.Any, | ||
) -> None: ... | ||
return _validator | ||
|
||
def _validate_elements( | ||
attribute: attr.Attribute[typing.Any], | ||
value: typing.Any, | ||
expected_type: typing.Optional[typing.Type[typing.Any]], | ||
) -> None: ... | ||
def _get_base_type( | ||
type_: typing.Type[typing.Any], | ||
) -> typing.Type[typing.Any]: ... | ||
def _type_matching( | ||
actual: typing.Type[typing.Any], expected: typing.Type[typing.Any] | ||
) -> bool: ... | ||
def _handle_callable( | ||
attribute: attr.Attribute[typing.Any], | ||
callable_: typing.Callable[..., typing.Any], | ||
expected_type: typing.Type[typing.Callable[..., typing.Any]], | ||
) -> None: ... | ||
def _handle_set_or_list( | ||
attribute: attr.Attribute[typing.Any], | ||
container: typing.Union[typing.Set[typing.Any], typing.List[typing.Any]], | ||
expected_type: typing.Union[ | ||
typing.Type[typing.Set[typing.Any]], | ||
typing.Type[typing.List[typing.Any]], | ||
], | ||
) -> None: ... | ||
def _handle_dict( | ||
attribute: attr.Attribute[typing.Any], | ||
container: typing.Union[ | ||
typing.Mapping[typing.Any, typing.Any], | ||
typing.MutableMapping[typing.Any, typing.Any], | ||
], | ||
expected_type: typing.Union[ | ||
typing.Type[typing.Mapping[typing.Any, typing.Any]], | ||
typing.Type[typing.MutableMapping[typing.Any, typing.Any]], | ||
], | ||
) -> None: ... | ||
def _handle_tuple( | ||
attribute: attr.Attribute[typing.Any], | ||
container: typing.Tuple[typing.Any], | ||
expected_type: typing.Type[typing.Tuple[typing.Any]], | ||
) -> None: ... | ||
def _handle_union( | ||
attribute: attr.Attribute[typing.Any], | ||
value: typing.Any, | ||
expected_type: typing.Type[typing.Any], | ||
) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ : str= ... |
Empty file.
Oops, something went wrong.