python / typing_extensions

Backported and experimental type hints for Python
Other
446 stars 110 forks source link

Add `typing.get_type_hints` backport #410

Closed cdce8p closed 2 months ago

cdce8p commented 6 months ago

Would it be worth backporting https://github.com/python/cpython/issues/114053 for Python 3.12.0 - 3.12.3? /CC @AlexWaygood

AlexWaygood commented 6 months ago

IIRC, backporting stuff that involves ForwardRef._evaluate() is pretty hard, because you end up having to copy a huge amount of typing internals into typing_extensions :(

So I'm not sure if it would be worth it just for the early 3.12 patch releases. But I'm definitely open to it if there's a way to do it that's not too fragile or complicated

AlexWaygood commented 2 months ago

I'm going to close this for now, as I don't think we have any plans to work on this considering that we think it would be quite involved to implement. However, we do now have typing_extensions.get_annotations(), which does similar things to typing.get_type_hints() without some of the... questionable behaviour that get_type_hints must maintain for backwards compatibility purposes :-)

(And I'd still be happy to review a PR if you can see a way to backport it in a non-horrible way!)