-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate the typing.io and typing.re pseudo-modules #82472
Comments
According to bpo-35089 (and the GitHub issues linked there), the typing.io and typing.re modules should no longer be used. Starting with Python 3.6, the typing documentation no longer mentions the typing.io and typing.re modules, and instead documents their contents as part of the main typing module. However, the typing module at runtime still supports typing.io and typing.re as before. Since these modules are not meant to be used anymore and are no longer documented, I would expect at least a DeprecationWarning when using them at runtime. The documentation on this could also be a bit clearer. As long as the modules are still supported at runtime, I would expect the documentation to mention that they still exist, but shouldn't be used anymore. In its current state, the documentation is confusing when coming from Python 3.5 (where typing.io and typing.re were the only documented way to access IO, Pattern, etc., but accessing typing.IO and typing.Pattern directly also works at runtime). |
Guido, what is your final opinion on this? |
The documentation (https://docs.python.org/3.10/library/typing.html#typing.BinaryIO) now mentions the typing.io and typing.re namespaces. I would prefer that they be deprecated and eventually completely removed. They don't work with most static type checkers. https://bugs.python.org/issue42001 makes the same points. |
I agree, these namespaces were a mistake. Let's start deprecating them (and remove their mention from the docs again). |
I opened a PR to remove their mention from the docs for now. I can look into how to add a deprecation warning to a module if no one else beats me to it. |
And I opened a second PR (for Python 3.11 only) to issue a deprecation warning when typing.io or typing.re gets imported. |
Hello Sebastian, the tests are failing on the Azure pipelines buildbot running appx tests: I suspect it's the same problem as this issue: Sending a PR shortly to test if that fixes it. |
Thank you for fixing this, Ken, the PR looks good to me. Overall it looks as if the the Azure pipeline should be fixed, though. It's not ideal that the tests pass while running the PR, but not in other situations. Also, the warnings suppression is not really obvious. |
I agree. This specific test only seems to run after a commit is made. I don't see a way to run this test on a PR, even the
Yup, it's hidden away in the docs here, so I was rather lost too: https://docs.python.org/3/library/warnings.html#testing-warnings Anyways, I'm not actually sure that the PR will fix it. AFAICS, the only way to test it is to commit it and let the buildbot run ;). I can't reproduce it locally. |
That specific buildbot is now green. Thanks everyone :)! I'm closing the issue now as it seems there isn't anything left to do. |
Ken: We still need to remove these modules in Python 3.12+. Should we open a separate issue, reopen this one, or just handle it after the Python 3.11 branch has been created? |
Woops, thanks for the reminder. I think both options are fine. But I'm leaning towards creating a new issue. The title of the current issue is "Deprecate the typing.io and typing.re pseudo-modules" not "Remove the typing.io and typing.re pseudo-modules" after all ;-). Jokes aside, the actual removal of a large chunk of code is usually quite contentious. And usually a lot of discussion happens when the time comes to remove it. So IMO having a separate issue for that when the time comes is better. |
This change seems to emit deprecation warnings in test_pydoc. PYTHONWARNINGS=always ./python.exe -Wall -m test test_pydoc
0:00:00 load avg: 2.57 Run tests sequentially
0:00:00 load avg: 2.57 [1/1] test_pydoc
/Users/kasingar/stuff/python/cpython/Lib/pydoc.py:1344: DeprecationWarning: typing.io is deprecated, import directly from typing instead. typing.io will be removed in Python 3.12.
if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
/Users/kasingar/stuff/python/cpython/Lib/pydoc.py:1344: DeprecationWarning: typing.re is deprecated, import directly from typing instead. typing.re will be removed in Python 3.12.
if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
test_pydoc passed in 31.6 sec == Tests result: SUCCESS == 1 test OK. Total duration: 31.7 sec |
test_typing emits them too as it tests importing things from __all__. |
Can that be fixed by changing test_pydoc? |
We could easily do what Ken did in PR-26811, and add "warnings.filterwarnings("default", category=DeprecationWarning)" to the test, but I would like to understand what is going on first. It seems the warnings are generated by test_builtin_with_more_than_four_children, which doesn't operate on typing directly. Here is a repro, without tests: srittau@blitz:~/Projekte/cpython (typing-io *)$ ./python -Wall
Python 3.11.0a0 (heads/main:17f94e2888, Jul 5 2021, 19:19:04) [GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydoc
>>> import typing
>>> doc = pydoc.TextDoc()
>>> x = doc.docclass(object)
/home/srittau/Projekte/cpython/Lib/pydoc.py:1344: DeprecationWarning: typing.io is deprecated, import directly from typing instead. typing.io will be removed in Python 3.12.
if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
/home/srittau/Projekte/cpython/Lib/pydoc.py:1344: DeprecationWarning: typing.re is deprecated, import directly from typing instead. typing.re will be removed in Python 3.12.
if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
>>> Same warning when calling "help(object)". This is not great. I assume that it is somehow related to pydoc.docclass() iterating over the the items of typing, but only if typing was imported. Please not that "io" and "re" are not part of typing.__all__. I will investigate more. |
pr-27039 suppresses warnings when accessing |
Why not just change "typing.io" to "typing"? |
typing.io is not referenced in either the tests or the implementation for pydoc. What happens is basically: typing.io is a class, so its derived from object. When formatting the docstring for object, the formatter queries the __module__ attribute of all sub-classes of object, including typing.io, so that it can include the sub-classes in its output: -------------- Help on class object in module builtins: class object -------------- Before the PR this failed, as accessing any typing.io.__module__ printed the warning. |
Thanks for the explanation. Let's reopen the issue for now. |
Currently deprecation warnings are emitted in test_typing: $ ./python -m test test_typing
0:00:00 load avg: 3.38 Run tests sequentially
0:00:00 load avg: 3.38 [1/1] test_typing
/home/serhiy/py/cpython/Lib/test/test_typing.py:4657: DeprecationWarning: typing.io is deprecated, import directly from typing instead. typing.io will be removed in Python 3.12.
k not in typing.io.__all__ and
/home/serhiy/py/cpython/Lib/test/test_typing.py:4658: DeprecationWarning: typing.re is deprecated, import directly from typing instead. typing.re will be removed in Python 3.12.
k not in typing.re.__all__ and == Tests result: SUCCESS == 1 test OK. Total duration: 564 ms |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: