-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add annotations and py.typed to conform with PEP561. Add type checking to tox #40
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the none check dropped here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure to be fair; I assume given the type checker does not complain it's not needed? @keiclone knows probably better