Closed devashishshankar closed 4 years ago
As mentioned in this doc section, pyfields
relies on whatever type checking library is available on your machine.
So if you have typeguard
or pytypes
installed, it should work correctly.
Ah, thanks! typeguard
works but is python3 only. And pytypes
doesn't work for py3.7. But these are already open issues in those libraries.
If I have a field with
type_hint
being something like List[A], and check_type=True, I would expect it to validate the field. However, the code throws the following error on class init:This seems to be the default behavior of
isinstance
when dealing with any subscripted generic field, for e.g. List[str] or Optional[str]. See related SO answer. Consequently validate also suffers with the same issue.There is an easy workaround, setting check_type=False, and adding a custom validator:
However, I still thought I would add this issue in case someone runs into it. (Don't know if this should be handled at a library level, given this is a limitation of the default
isinstance
)