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.

Title: In typing docs, note explicit import needed for IO and Pattern/Match
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: JelleZijlstra, Karl Kornel, docs@python, doerwalter, gvanrossum, levkivskyi, lukasz.langa, miss-islington, pablogsal
Priority: normal Keywords: patch

Created on 2019-10-02 18:31 by Karl Kornel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25821 merged JelleZijlstra, 2021-05-02 20:56
PR 25884 merged miss-islington, 2021-05-04 09:31
PR 25885 merged miss-islington, 2021-05-04 09:34
Messages (9)
msg353763 - (view) Author: Karl Kornel (Karl Kornel) Date: 2019-10-02 18:31

In, there is a note about the io and re classes not being included in typing.__all__.  I am a relatively new user of typing, and I did `from typing import *` in my code.  I ran the code through mypy first, which reported no problems, but then running Python 3.6 failed with a NameError (name 'IO' is not defined).

Reading through the typing source, it's clear that this was an intentional decision.  So, instead of reporting a bug, I'd like to request a documentation enhancement!

The docs for typing make no mention of or  So, my request is: In the sections for the IO/TextIO/BinaryIO and Pattern/Match classes, include text warning the user that these types are not imported when you do `from typing import *`.
msg353917 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-10-04 10:24
> So, my request is: In the sections for the IO/TextIO/BinaryIO and Pattern/Match classes, include text warning the user that these types are not imported when you do `from typing import *`.

I don't think this should really be a warning, probably just a note, but otherwise I totally agree. Would you like to make a PR?
msg382497 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2020-12-04 15:50
Shadowing the real modules `re` and `io` by

   from typing import *

would indeed be bad, but that argument IMHO doesn't hold for the types `IO`, `TextIO` and `BinaryIO`, yet they are not listed in `typing.__all__`. Is there a reason for that? And if not, could `IO`, `TextIO` and `BinaryIO` be added to `typing.__all__`?
msg382500 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-12-04 16:14
Wait, is the OP maybe that there’s a difference between typeshed an the stdlib
msg392731 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2021-05-02 20:56
It turns out that IO, TextIO, BinaryIO, Match, and Pattern aren't in typing.__all__. As Walter points out above, there's no clear reason for this. I am submitting a PR to add them to __all__.
msg392868 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-05-04 09:51
New changeset e1bcc88a502aa0239b6bcc4da3fe024307fd27f4 by Miss Islington (bot) in branch '3.10':
bpo-38352: Add to typing.__all__ (GH-25821) (#25884)
msg392869 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-05-04 10:02
New changeset 00726e51ade10c7e3535811eb700418725244230 by Miss Islington (bot) in branch '3.9':
bpo-38352: Add to typing.__all__ (GH-25821) (#25885)
msg392870 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-05-04 10:08
Fix merged to main (3.11), 3.10, and 3.9. Not applicable to older Pythons as they are security fixes only.
msg392894 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2021-05-04 13:37
@Łukasz thanks for your merging spree!

I'm actually not sure this should go into 3.9. Seems potentially dangerous that people upgrading from an earlier 3.9 patch release will now see new names injected into their namespace if they do `from typing import *`.
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82533
2021-07-18 15:30:54pablogsalsetpull_requests: - pull_request25772
2021-07-18 15:26:31pablogsalsetnosy: + pablogsal

pull_requests: + pull_request25772
2021-05-04 13:37:00JelleZijlstrasetmessages: + msg392894
2021-05-04 10:08:56lukasz.langasetstatus: open -> closed
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.6
messages: + msg392870

resolution: fixed
stage: patch review -> resolved
2021-05-04 10:02:52lukasz.langasetmessages: + msg392869
2021-05-04 09:51:45lukasz.langasetnosy: + lukasz.langa
messages: + msg392868
2021-05-04 09:34:48miss-islingtonsetpull_requests: + pull_request24559
2021-05-04 09:31:14miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request24558
2021-05-02 20:56:41JelleZijlstrasetkeywords: + patch
stage: patch review
pull_requests: + pull_request24508
2021-05-02 20:56:31JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg392731
2020-12-04 16:14:01gvanrossumsetmessages: + msg382500
2020-12-04 15:50:25doerwaltersetnosy: + doerwalter
messages: + msg382497
2019-10-04 10:24:29levkivskyisetmessages: + msg353917
2019-10-03 01:40:36xtreaksetnosy: + gvanrossum, levkivskyi
2019-10-02 18:31:17Karl Kornelcreate