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

Change typing.TYPE_CHECKING doc example #74160

Closed
Mortal mannequin opened this issue Apr 3, 2017 · 11 comments
Closed

Change typing.TYPE_CHECKING doc example #74160

Mortal mannequin opened this issue Apr 3, 2017 · 11 comments
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@Mortal
Copy link
Mannequin

Mortal mannequin commented Apr 3, 2017

BPO 29974
Nosy @berkerpeksag, @ilevkivskyi, @JelleZijlstra, @Mortal
PRs
  • bpo-29974: Change typing.TYPE_CHECKING doc example #982
  • [3.6] bpo-29974: Improve typing.TYPE_CHECKING example (GH-982) #1297
  • [3.5] bpo-29974: Improve typing.TYPE_CHECKING example (GH-982) #1299
  • 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 2017-04-26.14:28:41.505>
    created_at = <Date 2017-04-03.17:32:43.641>
    labels = ['type-bug', '3.7', 'docs']
    title = 'Change typing.TYPE_CHECKING doc example'
    updated_at = <Date 2017-04-26.15:21:38.194>
    user = 'https://github.com/Mortal'

    bugs.python.org fields:

    activity = <Date 2017-04-26.15:21:38.194>
    actor = 'levkivskyi'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2017-04-26.14:28:41.505>
    closer = 'berker.peksag'
    components = ['Documentation']
    creation = <Date 2017-04-03.17:32:43.641>
    creator = 'rav'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29974
    keywords = []
    message_count = 11.0
    messages = ['291085', '291101', '291121', '292332', '292334', '292351', '292352', '292353', '292354', '292361', '292362']
    nosy_count = 5.0
    nosy_names = ['docs@python', 'berker.peksag', 'levkivskyi', 'JelleZijlstra', 'rav']
    pr_nums = ['982', '1297', '1299']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29974'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @Mortal
    Copy link
    Mannequin Author

    Mortal mannequin commented Apr 3, 2017

    The documentation of typing.TYPE_CHECKING has an example (introduced in issue bpo-26141) that would lead to NameError at runtime. The example shows how to limit the import of "expensive_mod" to type checkers, but then goes on to use "expensive_mod.some_type" in a type annotation that is evaluated at runtime ("local_var: expensive_mod.some_type"). The use case of TYPE_CHECKING is probably meant for type annotations placed in comments, e.g. "local_var # type: expensive_mod.some_type".

    @Mortal Mortal mannequin added type-feature A feature request or enhancement 3.7 (EOL) end of life labels Apr 3, 2017
    @Mortal Mortal mannequin assigned docspython Apr 3, 2017
    @Mortal Mortal mannequin added the docs Documentation in the Doc dir label Apr 3, 2017
    @berkerpeksag berkerpeksag added type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels Apr 4, 2017
    @JelleZijlstra
    Copy link
    Member

    The example is actually correct; I just confirmed by running it in my shell. Type annotations on local variables are not evaluated at runtime; see PEP-526.

    @Mortal Mortal mannequin changed the title typing.TYPE_CHECKING doc example is incorrect Change typing.TYPE_CHECKING doc example Apr 4, 2017
    @Mortal
    Copy link
    Mannequin Author

    Mortal mannequin commented Apr 4, 2017

    I have updated the patch after feedback from Jelle Zijlstra and Ivan Levkevskyi. Indeed the example was correct; the patch now adds wording from PEP-484 and PEP-526 to clarify why a function parameter annotation needs to be in quotes and a local variable annotation does not.

    @berkerpeksag
    Copy link
    Member

    New changeset 87c07fe by Berker Peksag (Mathias Rav) in branch 'master':
    bpo-29974: Improve typing.TYPE_CHECKING example (GH-982)
    87c07fe

    @berkerpeksag
    Copy link
    Member

    87c07fe should still be backported to 3.5 and 3.6 branches so please don't close it yet.

    @berkerpeksag berkerpeksag reopened this Apr 26, 2017
    @ilevkivskyi
    Copy link
    Member

    87c07fe should still be backported to 3.5 and 3.6 branches so please don't close it yet.

    Thanks for making backport PRs! (and sorry for closing prematurely)

    @berkerpeksag
    Copy link
    Member

    New changeset 271a289 by Berker Peksag in branch '3.5':
    bpo-29974: Improve typing.TYPE_CHECKING example (GH-982)
    271a289

    @berkerpeksag
    Copy link
    Member

    New changeset 04f389b by Berker Peksag in branch '3.6':
    bpo-29974: Improve typing.TYPE_CHECKING example (GH-982)
    04f389b

    @berkerpeksag
    Copy link
    Member

    Now all backport PRs have been merged. Thanks for the PR, Mathias.

    Thanks for making backport PRs! (and sorry for closing prematurely)

    No problem, thanks for the reviews! By the way, sorry I missed the typo in your last name while doing the initial merge.

    @Mortal
    Copy link
    Mannequin Author

    Mortal mannequin commented Apr 26, 2017

    Sorry for making a typo in your last name, Ivan Levkivskyi! I should know better and use copy-and-paste.

    @ilevkivskyi
    Copy link
    Member

    Sorry for making a typo in your last name

    No problem!
    This actually happened maaany times with me :-)

    @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.7 (EOL) end of life docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants