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

Syntax quirk with variable annotations #79995

Closed
rhettinger opened this issue Jan 24, 2019 · 8 comments
Closed

Syntax quirk with variable annotations #79995

rhettinger opened this issue Jan 24, 2019 · 8 comments
Labels
3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@rhettinger
Copy link
Contributor

BPO 35814
Nosy @gvanrossum, @rhettinger, @ilevkivskyi, @pablogsal
PRs
  • bpo-35814: Allow same r.h.s. in annotated assignments as in normal ones #11667
  • bpo-35814: Allow same r.h.s. in annotated assignments as in normal ones #11667
  • bpo-35814: Allow same r.h.s. in annotated assignments as in normal ones #11667
  • bpo-35814: Update the annotated assignment docs #13757
  • bpo-35814: Allow unpacking in r.h.s of annotated assignment expressions #13760
  • bpo-35814: More updates to the annotated assignments docs #13794
  • 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 2019-01-25.02:48:43.473>
    created_at = <Date 2019-01-24.05:45:39.919>
    labels = ['interpreter-core', 'type-bug', '3.8']
    title = 'Syntax quirk with variable annotations'
    updated_at = <Date 2019-06-04.00:44:20.979>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2019-06-04.00:44:20.979>
    actor = 'levkivskyi'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-01-25.02:48:43.473>
    closer = 'levkivskyi'
    components = ['Interpreter Core']
    creation = <Date 2019-01-24.05:45:39.919>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35814
    keywords = ['patch', 'patch', 'patch']
    message_count = 8.0
    messages = ['334280', '334299', '334335', '342355', '342356', '342869', '342908', '344388']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'rhettinger', 'levkivskyi', 'pablogsal']
    pr_nums = ['11667', '11667', '11667', '13757', '13760', '13794']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue35814'
    versions = ['Python 3.8']

    @rhettinger
    Copy link
    Contributor Author

    Am not sure how much we care about this, but parenthesis around tuples stops being optional when there is a variable annotation.

    >>> from typing import Tuple
    >>> t = 10, 'hello'                     # Parens not normally required
    >>> t: Tuple[int, str] = (10, 'hello')  # Annotated allows parens
    >>> t: Tuple[int, str] = 10, 'hello'    # Annotated w/o parens fails
    SyntaxError: invalid syntax

    @rhettinger rhettinger added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 24, 2019
    @ilevkivskyi
    Copy link
    Member

    Good catch!

    I think it was just overlooked rather than a conscious decision (unlike the left hand side, that generated lots of debates)

    I will make a PR to allow everything that is allowed on r.h.s. of a normal assignment.

    @ilevkivskyi
    Copy link
    Member

    New changeset 62c35a8 by Ivan Levkivskyi in branch 'master':
    bpo-35814: Allow same r.h.s. in annotated assignments as in normal ones (GH-11667)
    62c35a8

    @ilevkivskyi ilevkivskyi added 3.8 only security fixes and removed 3.7 (EOL) end of life labels Jan 25, 2019
    @gvanrossum
    Copy link
    Member

    I think PEP-526 does not clarify the intention here. Perhaps we could add a specific example? It currently shows:

    t: Tuple[int, ...] = (1, 2, 3)

    We could just add this there:

    t: Tuple[int, ...] = 1, 2, 3

    @gvanrossum
    Copy link
    Member

    (With a comment indicating that the second is only accepted in Python 3.8 and later.)

    @ilevkivskyi
    Copy link
    Member

    Is PEP the best place for such updates? Maybe we can add a versionchanged note in https://docs.python.org/3/reference/simple_stmts.html#annotated-assignment-statements instead?

    @gvanrossum
    Copy link
    Member

    Is PEP the best place for such updates? Maybe we can add a versionchanged note in https://docs.python.org/3/reference/simple_stmts.html#annotated-assignment-statements instead?

    We should definitely update the docs, with versionchanged.

    But we should also update the PEP, because the reason this was changed was an interpretation issue in the PEP. This is different from simply changing things in a later version because we've come up with a new idea or we've learned that something was a bad idea.

    Now that the intention of the PEP has been clarified, the PEP itself ought to be updated with words expressing the clearer version; but because previously the intended syntax wasn't supported, it makes sense to also add a note there that this wasn't implemented correctly until 3.8.

    @pablogsal
    Copy link
    Member

    New changeset 8565f6b by Pablo Galindo in branch 'master':
    bpo-35814: Allow unpacking in r.h.s of annotated assignment expressions (GH-13760)
    8565f6b

    @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.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants