Open rkr-at-dbx opened 7 years ago
Maybe some undocumented internals of the typing module should be documented. Then this would be an issue for https://github.com/python/typing (or perhaps PEP 484 and https://github.com/python/cpython).
But maybe there's a quick solution: use a type alias instead of int
in the NewType()
call. E.g.
_Timestamp = int # May become e.g. float
Timestamp = NewType('Timestamp', _Timestamp)
Motivation: given output from (e.g.)
json
orsqlite3
, check that some part of it is properly typed, and wrap it in an appropriate NewType wrapper for use elsewhere.At present there seems to be no documented way to do the
isinstance
check, save to substituteint
directly. This will be incorrect ifTimestamp
's underlying implementation type changes; should it change tofloat
, mypy will not warn that_validate_timestamp
needs to be updated.As a workaround, one can currently rely on undocumented internals: