bloomberg / attrs-strict

Provides runtime validation of attributes specified in Python 'attr'-based data classes.
Apache License 2.0
52 stars 19 forks source link

fix: support types without args #108

Closed lucasrcezimbra closed 11 months ago

lucasrcezimbra commented 11 months ago

Issue number of the reported bug or feature request: no related issue.

Describe your changes The validator was not supporting types without args. For example:

>>> from unittest.mock import MagicMock
>>> from attrs_strict import type_validator
>>>
>>> attr = MagicMock()
>>> attr.name = "zoo"
>>> attr.type = list
>>>
>>> type_validator()(None, attr, [1, 2, 3])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
...
AttributeError: type object 'list' has no attribute '__args__'

This PR fixes it for lists, dicts, and tuples.

Testing performed Written tests.

gaborbernat commented 11 months ago

@lucasrcezimbra can you run pre-commit to fix the linting issues?