Skip to content
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

Merged
merged 4 commits into from May 27, 2019

Conversation

@mmaslowskicc
Copy link
Contributor

@mmaslowskicc mmaslowskicc commented May 24, 2019

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.

  • Added tests for changed code.
  • New features have been added to our Hypothesis testing strategy.
  • Changes or additions to public APIs are reflected in our type stubs (files ending in .pyi).
    • ...and used in the stub test file tests/typing_example.py.
  • Updated documentation for changed code.
    • New functions/classes have to be added to docs/api.rst by hand.
    • Changes to the signature of @attr.s() have to be added by hand too.
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Documentation in .rst files is written using semantic newlines.
  • Changes (and possible deprecations) have news fragments in 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!

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.
@euresti
Copy link
Contributor

@euresti euresti commented May 24, 2019

The stub changes make sense to me. Thanks for doing them!

@hynek
Copy link
Member

@hynek hynek commented May 24, 2019

Can you review and merge please? I’m traveling and I was gonna ping you anyways. :)

Copy link
Contributor

@euresti euresti left a comment

Thanks for doing this. Can you fix the 2 issues below?

@@ -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,
Copy link
Contributor

@euresti euresti May 24, 2019

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 = ...

) -> _ValidatorType[_T]: ...
key_validator: _ValidatorType[_K],
value_validator: _ValidatorType[_V],
mapping_validator: Optional[_ValidatorType[_M]] = None,
Copy link
Contributor

@euresti euresti May 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@euresti euresti merged commit 45adbb9 into python-attrs:master May 27, 2019
3 checks passed
@euresti
Copy link
Contributor

@euresti euresti commented May 27, 2019

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants