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

Mapping type should be passed to _handle_dict #27

Closed
anentropic opened this issue Mar 4, 2020 · 4 comments
Closed

Mapping type should be passed to _handle_dict #27

anentropic opened this issue Mar 4, 2020 · 4 comments

Comments

@anentropic
Copy link

elif base_type in {
        dict,
        collections.OrderedDict,
        collections.defaultdict,
        typing.Dict,
        typing.DefaultDict,
    }:
        _handle_dict(attribute, value, expected_type)

this list of types should include typing.Mapping

Mapping[<keyT>, <valueT>] are not caught by any of the checks so they fall-thru i.e. always succeed

@anentropic
Copy link
Author

also, validating a type like Dict[str, Any] gives an error:

/VENV/lib/python2.7/site-packages/attrs_strict/_type_validation.pyc in _validate_elements(attribute, value, expected_type)
     35         return
     36
---> 37     if base_type != typing.Union and not isinstance(value, base_type):
     38         raise AttributeTypeError(value, attribute)
     39

/VENV/lib/python2.7/site-packages/typing.pyc in __instancecheck__(self, obj)
    632
    633     def __instancecheck__(self, obj):
--> 634         raise TypeError("Any cannot be used with isinstance().")
    635
    636     def __subclasscheck__(self, cls):

TypeError: Any cannot be used with isinstance().

@erikseulean
Copy link
Contributor

Thanks for opening this @anentropic . I'll have a look at this and come back!

@erikseulean
Copy link
Contributor

@anentropic I added the MutableMapping and Mapping types and fixed the typing.Any issue. Thanks for reporting this.
I'll have a sweep through the collections library and improve the support for other types existing sometimes soon.

@erikseulean
Copy link
Contributor

New version available, including this changes: https://pypi.org/project/attrs-strict/

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

No branches or pull requests

2 participants