-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
Fix deep_iterable, deep_mapping validator type stubs #533
Conversation
Use bound type variables for iterables and mappings of the validated item types, so mypy does not erroneously require both the iterable attribute validated by deep_iterable and the item type validated by the first argument of deep_iterable to have the same type. Do not require optional arguments in type stubs.
The stub changes make sense to me. Thanks for doing them! |
Can you review and merge please? I’m traveling and I was gonna ping you anyways. :) |
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.
Thanks for doing this. Can you fix the 2 issues below?
src/attr/validators.pyi
Outdated
@@ -14,11 +29,11 @@ def in_(options: Container[_T]) -> _ValidatorType[_T]: ... | |||
def and_(*validators: _ValidatorType[_T]) -> _ValidatorType[_T]: ... | |||
def deep_iterable( | |||
member_validator: _ValidatorType[_T], | |||
iterable_validator: Optional[_ValidatorType[_T]], | |||
) -> _ValidatorType[_T]: ... | |||
iterable_validator: Optional[_ValidatorType[_I]] = None, |
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.
I know the default value is actually None
but in stubs you usually just write = ...
src/attr/validators.pyi
Outdated
) -> _ValidatorType[_T]: ... | ||
key_validator: _ValidatorType[_K], | ||
value_validator: _ValidatorType[_V], | ||
mapping_validator: Optional[_ValidatorType[_M]] = None, |
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.
Same here
Thanks for the fix! |
Use bound type variables for iterables and mappings of the validated item types, so mypy does not erroneously require
both the iterable attribute validated by deep_iterable and the item type validated by the first argument of
deep_iterable to have the same type. This fixes #531.
Do not require optional arguments in type stubs.
Pull Request Check List
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
.pyi
).tests/typing_example.py
.docs/api.rst
by hand.@attr.s()
have to be added by hand too.versionadded
,versionchanged
, ordeprecated
directives..rst
files is written using semantic newlines.changelog.d
.If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!