Skip to content
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

In typing docs, note explicit import needed for IO and Pattern/Match #82533

Closed
KarlKornel mannequin opened this issue Oct 2, 2019 · 9 comments
Closed

In typing docs, note explicit import needed for IO and Pattern/Match #82533

KarlKornel mannequin opened this issue Oct 2, 2019 · 9 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@KarlKornel
Copy link
Mannequin

KarlKornel mannequin commented Oct 2, 2019

BPO 38352
Nosy @gvanrossum, @doerwalter, @ambv, @ilevkivskyi, @JelleZijlstra, @pablogsal, @miss-islington
PRs
  • bpo-38352: Add to typing.__all__ #25821
  • [3.10] bpo-38352: Add to typing.__all__ (GH-25821) #25884
  • [3.9] bpo-38352: Add to typing.__all__ (GH-25821) #25885
  • 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:

    assignee = None
    closed_at = <Date 2021-05-04.10:08:56.605>
    created_at = <Date 2019-10-02.18:31:17.565>
    labels = ['3.11', 'type-bug', '3.9', '3.10', 'docs']
    title = 'In typing docs, note explicit import needed for IO and Pattern/Match'
    updated_at = <Date 2021-07-18.15:30:54.926>
    user = 'https://bugs.python.org/KarlKornel'

    bugs.python.org fields:

    activity = <Date 2021-07-18.15:30:54.926>
    actor = 'pablogsal'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2021-05-04.10:08:56.605>
    closer = 'lukasz.langa'
    components = ['Documentation']
    creation = <Date 2019-10-02.18:31:17.565>
    creator = 'Karl Kornel'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38352
    keywords = ['patch']
    message_count = 9.0
    messages = ['353763', '353917', '382497', '382500', '392731', '392868', '392869', '392870', '392894']
    nosy_count = 9.0
    nosy_names = ['gvanrossum', 'doerwalter', 'docs@python', 'lukasz.langa', 'levkivskyi', 'JelleZijlstra', 'pablogsal', 'Karl Kornel', 'miss-islington']
    pr_nums = ['25821', '25884', '25885']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue38352'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @KarlKornel
    Copy link
    Mannequin Author

    KarlKornel mannequin commented Oct 2, 2019

    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 *.

    @KarlKornel KarlKornel mannequin assigned docspython Oct 2, 2019
    @KarlKornel KarlKornel mannequin added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Oct 2, 2019
    @ilevkivskyi
    Copy link
    Member

    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?

    @doerwalter
    Copy link
    Contributor

    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__?

    @gvanrossum
    Copy link
    Member

    Wait, is the OP maybe that there’s a difference between typeshed an the stdlib typing.py?

    @JelleZijlstra
    Copy link
    Member

    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__.

    @ambv
    Copy link
    Contributor

    ambv commented May 4, 2021

    New changeset e1bcc88 by Miss Islington (bot) in branch '3.10':
    bpo-38352: Add to typing.__all__ (GH-25821) (bpo-25884)
    e1bcc88

    @ambv
    Copy link
    Contributor

    ambv commented May 4, 2021

    New changeset 00726e5 by Miss Islington (bot) in branch '3.9':
    bpo-38352: Add to typing.__all__ (GH-25821) (bpo-25885)
    00726e5

    @ambv
    Copy link
    Contributor

    ambv commented May 4, 2021

    Fix merged to main (3.11), 3.10, and 3.9. Not applicable to older Pythons as they are security fixes only.

    @ambv ambv added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels May 4, 2021
    @ambv ambv closed this as completed May 4, 2021
    @JelleZijlstra
    Copy link
    Member

    @Ł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 *.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants