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

Attrs typing inference does not work with types from the typing module #2091

Closed
Meallia opened this issue Sep 16, 2019 · 0 comments
Closed
Labels
bug something is clearly wrong here

Comments

@Meallia
Copy link
Contributor

Meallia commented Sep 16, 2019

When trying to use builds or from_type strategies with an attrs class using generic classes from the typing module such as List[x], Union[x,y] or Dict[x,y] hypothesis fails.

Trying to create a strategy from this class:

@attr.s
class Inferrables(object):
    type_typing_list = attr.ib(type=typing.List[int])
    type_typing_dict = attr.ib(type=typing.Dict[str, int])
    type_typing_union = attr.ib(type=typing.Union[str, int])

@given(st.from_type(Inferrables))
def test_attrs_inference_from_type(c):
    pass

Would fail with

hypothesis.errors.ResolutionFailed: Cannot infer a strategy from the default, validator, type, or converter for attribute=Attribute(name='type_typing_union', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=typing.Union[str, int], converter=None, kw_only=False) of class=<class 'tests.cover.test_attrs_inference.Inferrables'>

@Zac-HD Zac-HD added the bug something is clearly wrong here label Sep 17, 2019
@Zac-HD Zac-HD closed this as completed Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

No branches or pull requests

2 participants