Add support for NewType, typing.List, typing.Dict type hinting
A NewType definition will fail the inspect.isclass check. Retrieving and using the __supertype__ will potentially fix this.
Example.
from typing import NewType, Dict
UserId = NewType("UserId", int)
DUserDataset = Dataset["user": UserId, "properties": Dict[str, str]]
Hi @martijnlentink ,
Thank you for the pull request, great additions.
Unfortunately I can't make it work. I tried Python 3.6, 3.7, 3.8, and on all it seems NewType is not something you can apply isinstance on.
Here is the unit test that I wrote, does it work for you?
def test_validate_newtype():
from typing import NewType
UserId = NewType('UserId', int)
df = pd.DataFrame(dict(a=[UserId(1), UserId(2), UserId(3)], b=["a","b","c"]))
@validate
def process(data: Dataset["a": UserId, "b": object]):
pass
process(df)
Hmm, you are right. I should've mentioned that I did not have time to test it yet 🙈. Maybe change the isinstance check to hasattr(stop_type, "__supertype__"). What do you think?
I haven't found any other way that works, so I would say yes let's go with this
Okay, done. Let me know if you want me to squash my commits 👍
Are we able to merge this to production?