New submission from Karl Kornel karl@kornel.us:
Hello!
In https://github.com/python/cpython/blob/master/Lib/typing.py#L115-L117, 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 typing.io or typing.re. 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 *`.
---------- assignee: docs@python components: Documentation messages: 353763 nosy: Karl Kornel, docs@python priority: normal severity: normal status: open title: In typing docs, note explicit import needed for IO and Pattern/Match type: behavior versions: Python 3.6
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Change by Karthikeyan Singaravelan tir.karthi@gmail.com:
---------- nosy: +gvanrossum, levkivskyi
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Ivan Levkivskyi levkivskyi@gmail.com added the comment:
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?
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Walter Dörwald walter@livinglogic.de added the comment:
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__`?
---------- nosy: +doerwalter
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Guido van Rossum guido@python.org added the comment:
Wait, is the OP maybe that there’s a difference between typeshed an the stdlib typing.py?
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Jelle Zijlstra jelle.zijlstra@gmail.com added the comment:
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__.
---------- nosy: +Jelle Zijlstra
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Change by Jelle Zijlstra jelle.zijlstra@gmail.com:
---------- keywords: +patch pull_requests: +24508 stage: -> patch review pull_request: https://github.com/python/cpython/pull/25821
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- nosy: +miss-islington nosy_count: 6.0 -> 7.0 pull_requests: +24558 pull_request: https://github.com/python/cpython/pull/25884
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- pull_requests: +24559 pull_request: https://github.com/python/cpython/pull/25885
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Łukasz Langa lukasz@langa.pl added the comment:
New changeset e1bcc88a502aa0239b6bcc4da3fe024307fd27f4 by Miss Islington (bot) in branch '3.10': bpo-38352: Add to typing.__all__ (GH-25821) (#25884) https://github.com/python/cpython/commit/e1bcc88a502aa0239b6bcc4da3fe024307f...
---------- nosy: +lukasz.langa
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Łukasz Langa lukasz@langa.pl added the comment:
New changeset 00726e51ade10c7e3535811eb700418725244230 by Miss Islington (bot) in branch '3.9': bpo-38352: Add to typing.__all__ (GH-25821) (#25885) https://github.com/python/cpython/commit/00726e51ade10c7e3535811eb7004187252...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Łukasz Langa lukasz@langa.pl added the comment:
Fix merged to main (3.11), 3.10, and 3.9. Not applicable to older Pythons as they are security fixes only.
---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.6
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________
Jelle Zijlstra jelle.zijlstra@gmail.com added the comment:
@Ł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 *`.
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue38352 _______________________________________