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

Typing issue with deep_iterable validator #531

Closed
mcyprian opened this issue May 15, 2019 · 0 comments · Fixed by #533
Closed

Typing issue with deep_iterable validator #531

mcyprian opened this issue May 15, 2019 · 0 comments · Fixed by #533

Comments

@mcyprian
Copy link

When I run mypy check on the following code:

import attr
from attr.validators import deep_iterable, instance_of
from typing import List


@attr.s
class Example(object):
    x = attr.ib(
        type=List[int],
        validator=deep_iterable(instance_of(int), instance_of(list))
    )

it results in:

script.py:11: error: Cannot infer type argument 1 of "deep_iterable"
script.py:11: error: Argument 1 to "instance_of" has incompatible type "Type[int]"; expected "Union[Tuple[Type[List[int]], ...], Type[List[int]]]"
script.py:11: error: Argument 1 to "instance_of" has incompatible type "Type[List[Any]]"; expected "Union[Tuple[Type[List[int]], ...], Type[List[int]]]"

mypy == 0.670, attrs == 19.1.0

mmaslowskicc added a commit to mmaslowskicc/attrs that referenced this issue 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.
mmaslowskicc added a commit to mmaslowskicc/attrs that referenced this issue 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.

Do not require optional arguments in type stubs.
euresti pushed a commit that referenced this issue May 27, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant