This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Deprecate the typing.io and typing.re pseudo-modules
Type: behavior Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: JelleZijlstra, dgelessus, docs@python, gvanrossum, kj, levkivskyi, lukasz.langa, miss-islington, serhiy.storchaka, srittau, xtreak
Priority: normal Keywords: patch

Created on 2019-09-27 11:48 by dgelessus, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26113 merged srittau, 2021-05-13 21:53
PR 26719 merged srittau, 2021-06-14 12:57
PR 26720 merged miss-islington, 2021-06-14 14:45
PR 26721 merged miss-islington, 2021-06-14 14:45
PR 26811 merged kj, 2021-06-20 17:29
PR 27039 merged srittau, 2021-07-05 17:49
PR 27312 merged srittau, 2021-07-23 18:05
PR 27872 merged kj, 2021-08-21 14:30
PR 27907 merged miss-islington, 2021-08-23 17:13
Messages (28)
msg353356 - (view) Author: (dgelessus) * Date: 2019-09-27 11:48
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).
msg353400 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-09-27 20:09
Guido, what is your final opinion on this?
msg392730 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2021-05-02 20:39
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.
msg393611 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-05-13 21:37
I agree, these namespaces were a mistake. Let's start deprecating them (and remove their mention from the docs again).
msg393613 - (view) Author: Sebastian Rittau (srittau) * Date: 2021-05-13 21:54
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.
msg395794 - (view) Author: Sebastian Rittau (srittau) * Date: 2021-06-14 12:58
And I opened a second PR (for Python 3.11 only) to issue a deprecation warning when typing.io or typing.re gets imported.
msg395800 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-06-14 14:45
New changeset 8a76683cfb842e12b57f6d276839f6c68fd94e1a by Sebastian Rittau in branch 'main':
bpo-38291: Remove mention of typing.io and typing.re again (GH-26113)
https://github.com/python/cpython/commit/8a76683cfb842e12b57f6d276839f6c68fd94e1a
msg395803 - (view) Author: miss-islington (miss-islington) Date: 2021-06-14 15:06
New changeset fc310cb862ce0411bb5daed37f7f31b75647495b by Miss Islington (bot) in branch '3.10':
bpo-38291: Remove mention of typing.io and typing.re again (GH-26113)
https://github.com/python/cpython/commit/fc310cb862ce0411bb5daed37f7f31b75647495b
msg395805 - (view) Author: miss-islington (miss-islington) Date: 2021-06-14 15:07
New changeset 7f021952b2debb51306f70ec96a94ecc7fbffc19 by Miss Islington (bot) in branch '3.9':
bpo-38291: Remove mention of typing.io and typing.re again (GH-26113)
https://github.com/python/cpython/commit/7f021952b2debb51306f70ec96a94ecc7fbffc19
msg396147 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-06-19 17:31
New changeset 09eb81711597725f853e4f3b659ce185488b0d8c by Sebastian Rittau in branch 'main':
bpo-38291: DeprecationWarning when importing typing.{io,re} (#26719)
https://github.com/python/cpython/commit/09eb81711597725f853e4f3b659ce185488b0d8c
msg396183 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-06-20 17:29
Hello Sebastian, the tests are failing on the Azure pipelines buildbot running appx tests:

https://dev.azure.com/Python/cpython/_build/results?buildId=82827&view=logs&j=0fcf9c9b-89fc-526f-8708-363e467e119e&t=fa5ef4ee-3911-591e-4444-19482ab189b7

I suspect it's the same problem as this issue:
https://bugs.python.org/issue44451

Sending a PR shortly to test if that fixes it.
msg396217 - (view) Author: Sebastian Rittau (srittau) * Date: 2021-06-21 10:01
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.
msg396219 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-06-21 10:15
> 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.

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 `test-with-buildbots` test doesn't seem to trigger it.

> Also, the warnings suppression is not really obvious.

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.
msg396317 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-06-22 10:04
That specific buildbot is now green. Thanks everyone :)!
https://dev.azure.com/Python/cpython/_build/results?buildId=82931&view=results

I'm closing the issue now as it seems there isn't anything left to do.
msg396322 - (view) Author: Sebastian Rittau (srittau) * Date: 2021-06-22 11:25
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?
msg396324 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-06-22 12:14
@Sebastian,

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.
msg396968 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2021-07-05 04:33
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
Tests result: SUCCESS
msg396975 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-07-05 09:04
> This change seems to emit deprecation warnings in test_pydoc.

test_typing emits them too as it tests importing things from __all__.
msg397001 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-07-05 15:58
Can that be fixed by changing test_pydoc?
msg397012 - (view) Author: Sebastian Rittau (srittau) * Date: 2021-07-05 17:38
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.
msg397013 - (view) Author: Sebastian Rittau (srittau) * Date: 2021-07-05 17:52
pr-27039 suppresses warnings when accessing `typing.{re,io}.__module__`, which should fix this warning.
msg397016 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-07-05 18:34
Why not just change "typing.io" to "typing"?
msg397018 - (view) Author: Sebastian Rittau (srittau) * Date: 2021-07-05 19:40
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
 |  The base class of the class hierarchy.
 |  
 |  When called, it accepts no arguments and returns a new featureless
 |  instance that has no instance attributes and cannot be given any.
 |  
 |  Built-in subclasses:
 |      anext_awaitable
 |      async_generator
 |      async_generator_asend
 |      async_generator_athrow
 |      ... and 88 other subclasses
 |  
[...]

--------------

Before the PR this failed, as accessing any typing.io.__module__ printed the warning.
msg397020 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-07-05 20:42
Thanks for the explanation. Let's reopen the issue for now.
msg397042 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-07-06 15:01
New changeset 8b849ea0f3482ad834e7989ff474dd5db2f295c8 by Sebastian Rittau in branch 'main':
bpo-38291: Fix a spurious warning when using help(object) (#27039)
https://github.com/python/cpython/commit/8b849ea0f3482ad834e7989ff474dd5db2f295c8
msg398082 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-23 17:28
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
Tests result: SUCCESS
msg400151 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-08-23 17:13
New changeset 1a995b0ceefdf7eb59963f3ab395c47d8da226e3 by Ken Jin in branch 'main':
bpo-38291: Update 3.10 WhatsNew with typing.{io|re} DeprecationWarning (GH-27872)
https://github.com/python/cpython/commit/1a995b0ceefdf7eb59963f3ab395c47d8da226e3
msg400152 - (view) Author: miss-islington (miss-islington) Date: 2021-08-23 17:32
New changeset 27f2f62ad490afc8e4dd6d80351916a9d06b97e3 by Miss Islington (bot) in branch '3.10':
bpo-38291: Update 3.10 WhatsNew with typing.{io|re} DeprecationWarning (GH-27872)
https://github.com/python/cpython/commit/27f2f62ad490afc8e4dd6d80351916a9d06b97e3
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82472
2021-08-23 17:32:39miss-islingtonsetmessages: + msg400152
2021-08-23 17:13:59miss-islingtonsetpull_requests: + pull_request26363
2021-08-23 17:13:59lukasz.langasetnosy: + lukasz.langa
messages: + msg400151
2021-08-21 14:30:39kjsetpull_requests: + pull_request26327
2021-07-24 04:12:34kjsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-07-23 18:05:30srittausetstage: needs patch -> patch review
pull_requests: + pull_request25857
2021-07-23 17:28:04serhiy.storchakasetstatus: closed -> open

assignee: docs@python ->

nosy: + serhiy.storchaka
messages: + msg398082
resolution: fixed -> (no value)
stage: resolved -> needs patch
2021-07-06 17:24:37gvanrossumsetstatus: open -> closed
2021-07-06 15:01:20gvanrossumsetmessages: + msg397042
2021-07-05 20:42:04gvanrossumsetstatus: closed -> open

messages: + msg397020
2021-07-05 19:40:12srittausetmessages: + msg397018
2021-07-05 18:34:28gvanrossumsetmessages: + msg397016
2021-07-05 17:52:46srittausetmessages: + msg397013
2021-07-05 17:49:01srittausetpull_requests: + pull_request25599
2021-07-05 17:38:16srittausetmessages: + msg397012
2021-07-05 15:58:42gvanrossumsetmessages: + msg397001
2021-07-05 09:04:57kjsetmessages: + msg396975
2021-07-05 04:33:42xtreaksetnosy: + xtreak
messages: + msg396968
2021-06-22 12:14:51kjsetmessages: + msg396324
2021-06-22 11:25:22srittausetmessages: + msg396322
2021-06-22 10:04:58kjsetstatus: open -> closed
resolution: fixed
messages: + msg396317

stage: patch review -> resolved
2021-06-21 10:15:46kjsetmessages: + msg396219
2021-06-21 10:01:14srittausetmessages: + msg396217
2021-06-20 17:29:56kjsetpull_requests: + pull_request25393
2021-06-20 17:29:39kjsetnosy: + kj
messages: + msg396183
2021-06-19 17:31:25gvanrossumsetmessages: + msg396147
2021-06-14 15:07:08miss-islingtonsetmessages: + msg395805
2021-06-14 15:06:37miss-islingtonsetmessages: + msg395803
2021-06-14 14:45:33miss-islingtonsetpull_requests: + pull_request25310
2021-06-14 14:45:28miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25308
2021-06-14 14:45:27gvanrossumsetmessages: + msg395800
2021-06-14 12:58:03srittausetmessages: + msg395794
2021-06-14 12:57:09srittausetpull_requests: + pull_request25307
2021-05-13 21:54:30srittausetmessages: + msg393613
2021-05-13 21:53:18srittausetkeywords: + patch
stage: patch review
pull_requests: + pull_request24757
2021-05-13 21:37:39gvanrossumsetmessages: + msg393611
versions: - Python 3.10
2021-05-03 10:28:51srittausetnosy: + srittau
2021-05-02 20:39:57JelleZijlstrasetnosy: + JelleZijlstra
title: Unclear status of the typing.io and typing.re pseudo-modules in docs and runtime -> Deprecate the typing.io and typing.re pseudo-modules
messages: + msg392730

versions: + Python 3.10, Python 3.11, - Python 3.6, Python 3.7, Python 3.8, Python 3.9
2019-09-27 20:09:08levkivskyisetnosy: + gvanrossum, levkivskyi
messages: + msg353400
2019-09-27 11:48:37dgelessuscreate