Open issue: typing_objects
function definitions
#14
Labels
open issues
Open issues to be discussed with other users of the runtime typing ecosystem
Currently,
typing-inspection
works on the supported Python versions (3.9-3.14) and has a lower bound ontyping-extensions
:typing-inspection/pyproject.toml
Lines 31 to 33 in 168c1e4
Version
4.12.0
was released almost a year ago, so it seemed reasonable to choose it as a lower bound. In the future, it would be great iftyping-extensions
could keep this lower bound as long as possible. This means that thetyping_objects
inspection functions need to handle several different cases. For a typing memberTypingObj
:typing.TypingObj
andtyping_extensions.TypingObj
exist.typing_extensions
is simply reexportingtyping.TypingObj
, in this case,typing_objects.is_typingobj()
can be implemented as:typing_extensions
backports a different version ofTypingObj
. In this case, the check can be implemented as:typing_extensions.TypingObj
exists (e.g. when not on the latest Python version):typing.TypingObj
exists (e.g. when not on the latesttyping_extensions
version):TypingObj
doesn't exist in both modules:Several options are offered to us to implement the checks:
hasattr()
/sys.version_info
checks to define the functions. This can get repetitive and unreadable very quickly.hasattr()
/sys.version_info
checks in the function. This could degrade performance slightly (in Pydantic, we rely a lot on thes introspection functions, and noticed small performance improvements (~1-5%) when optimizing them)._compile_identity_check_function()
/_compile_isinstance_check_function()
are currently doing.The chosen approach works fine, but requires generating typing stubs, and conceptually feels a bit hacky (functions are generated using
exec()
). I'm open to suggestions that would provide a cleaner implementation without hurting performance.The text was updated successfully, but these errors were encountered: