-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type stubs and py.typed. Add type checking to tox
Signed-off-by: Wilfred Wong <[email protected]>
- Loading branch information
Showing
11 changed files
with
199 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ __pycache__ | |
/.vscode | ||
|
||
# tools | ||
/.*_cache | ||
.*_cache | ||
|
||
|
||
pip-wheel-metadata |
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,3 @@ | ||
include attrs_strict/py.typed | ||
recursive-include attrs_strict *.pyi | ||
recursive-include attrs_strict *.py |
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
Empty file.
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
author_email="[email protected]", | ||
license="Apache 2.0", | ||
packages=["attrs_strict"], | ||
include_package_data=True, | ||
install_requires=["attrs", "typing; python_version<'3.5'"], | ||
tests_require=["mock", "pytest"], | ||
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4", | ||
|
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,2 @@ | ||
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 |
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
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
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: ... |