Closed tmke8 closed 4 years ago
Hi, I have a (maybe unusual) situation where I do a cast but the result will not pass the isinstance check. A minimal example:
isinstance
from dataclasses import dataclass from typing import NewType import dacite UserId = NewType("UserId", int) @dataclass class Config: user_id: UserId dacite.from_dict(data_class=Config, data={"user_id": 3}, config=dacite.Config(cast=[UserId]))
In this case, isinstance(user_id, UserId) will fail, because NewType has no effect at runtime (it's purely for static type checking).
isinstance(user_id, UserId)
NewType
I would argue that if a cast was performed, the user knows what they're doing and the isinstance check is not needed anyway.
If this sounds reasonable to you, I'd be happy to make the code changes and send a PR.
Never mind actually. It does work if you don't do other weird things (like I did).
Hi, I have a (maybe unusual) situation where I do a cast but the result will not pass the
isinstance
check. A minimal example:In this case,
isinstance(user_id, UserId)
will fail, becauseNewType
has no effect at runtime (it's purely for static type checking).I would argue that if a cast was performed, the user knows what they're doing and the
isinstance
check is not needed anyway.If this sounds reasonable to you, I'd be happy to make the code changes and send a PR.