typing icon indicating copy to clipboard operation
typing copied to clipboard

Will `typing.Tuple` die "in the first Python version released 5 years after the release of Python 3.9.0"?

Open junkmd opened this issue 3 years ago • 4 comments

I am developing some python-version-compatible library.

I was using only typing.Tuple for hinting. But this way is depreciated by PEP585. So I set up a conditional branch to use the built-in type tuple unless sys.version_info < (3, 9).

The type checker did not work well this way, so I submitted microsoft/pylance-release#3066 for help.

From the discussion, "It would be way too disruptive to delete these symbols from typing", so I was trying to eliminate the conditional branch.

However, some members of this repository have commented they will ”be removed". https://github.com/python/typing/issues/948#issuecomment-972908188

And there are a number of things that could be interpreted for me as "the definition of Tuple in the namespace of the typing module will be removed" in some documentations. https://docs.python.org/3/library/typing.html#module-contents https://peps.python.org/pep-0585/#implementation

I was upset.

Does the above wording mean that the definition in the typing module will replace from Tuple = _TupleType(tuple, -1, inst=False, name='Tuple') to (such as) from builtins import tuple as Tuple?

Or will the definition named Tuple be removed?

junkmd avatar Aug 02 '22 08:08 junkmd

There are currently no plans to remove the aliases from typing. But using the built-in generics - if possible - is certainly more future-proof. For now, it's perfectly fine to continue using the aliases from typing, although you should consider starting to use the built-in generics when dropping support for Python versions before 3.9.

srittau avatar Aug 02 '22 09:08 srittau

@srittau

Thank you for your response.

There are currently no plans to remove the aliases from typing.

I am glad to hear that.

junkmd avatar Aug 02 '22 09:08 junkmd

And just to clarify: I expect that the aliases will be removed at some point, but I don't think we will even start to issue deprecation warnings before the end of life of Python 3.8 (at the end of 2024) as this would indeed be too disruptive. And even then I can see these types to have a fairly long deprecation period.

srittau avatar Aug 02 '22 09:08 srittau

See here for some related recent discussion: https://discuss.python.org/t/concern-about-pep-585-removals/15901

AlexWaygood avatar Aug 02 '22 09:08 AlexWaygood

PEP585 has been updated by python/peps#2778.

My fears have been taken away.

Thanks for responses.

junkmd avatar Sep 15 '22 14:09 junkmd

Thank you for bringing this up.

srittau avatar Sep 15 '22 14:09 srittau