[issue34568] Types in `typing` not anymore instances of `type` or subclasses of "real" types
Ivan Levkivskyi
report at bugs.python.org
Thu Sep 6 06:01:32 EDT 2018
Ivan Levkivskyi <levkivskyi at gmail.com> added the comment:
> but even then types in the typing could themselves implement `__instancecheck__` and `__subclasscheck__` and retain the old behavior.
It doesn't work that way. `__instancecheck__` and `__subclasscheck__` tweaks the behaviour of superclass (i.e. the right argument) in `isinstance()` and `issubclass()`. This is how `isinstance([], typing.Iterable)` works, you can't use the same to tweak `isinstance(typing.Iterable, type)`.
> Hopefully someone with more insight on this can comment my worries. Perhaps the attribute should also be documented as discussed earlier: https://github.com/python/typing/issues/335
No, it is not safe to use it and will not be documented. You missed the point of my previous post, the idea is to add public wrappers in typing that will hide `__origin__` (or whatever else) as an implementation detail. Using `__origin__` is OK however as a *temporary* measure, if you don't want to use `typing_inspect` in the meantime.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34568>
_______________________________________
More information about the Python-bugs-list
mailing list