GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Walrus Operator in list index · Issue #86482 · python/cpython

Walrus Operator in list index #86482

New issue
Copy link
New issue
Copy link
Closed
Closed
Walrus Operator in list index#86482
Copy link
Assignees
JelleZijlstra
Labels
3.10 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)

Description

Brando753
mannequin
opened on Nov 10, 2020
Issue body actions
BPO 42316
Nosy @terryjreedy, @lysnikolaou
PRs
  • gh-86482: Document assignment expression need for ()s #23291
  • bpo-42316: Allow unparenthesized walrus operator in indexes #23317
  • 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 = None
    created_at = <Date 2020-11-10.17:28:35.243>
    labels = ['interpreter-core', '3.10', 'docs']
    title = 'Walrus Operator in list index'
    updated_at = <Date 2020-11-16.23:09:41.621>
    user = 'https://bugs.python.org/Brando753'

    bugs.python.org fields:

    activity = <Date 2020-11-16.23:09:41.621>
    actor = 'lys.nikolaou'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation', 'Interpreter Core']
    creation = <Date 2020-11-10.17:28:35.243>
    creator = 'Brando753'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42316
    keywords = ['patch']
    message_count = 3.0
    messages = ['380691', '380970', '381179']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'docs@python', 'lys.nikolaou', 'Brando753']
    pr_nums = ['23291', '23317']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue42316'
    versions = ['Python 3.10']

    Activity

    Next
    1. Brando753 commented on Nov 10, 2020

      @Brando753
      Brando753mannequin
      on Nov 10, 2020
      MannequinAuthor
      More actions

      Reading the PEP-572 document I don't see anything stating that Walrus operator in list indexes must be enclosed in parenthesis.

      Minimal Example:
      '''
      In [1]: a = list(range(10))

      In [2]: idx = -1

      In [3]: a[idx := idx +1]
      File "<ipython-input-3-65fc931e77dd>", line 1
      a[idx := idx +1]
      ^
      SyntaxError: invalid syntax

      '''

      If you enclose in parenthesis it works as expected:
      '''
      In [4]: a[(idx := idx +1)]
      Out[4]: 0

      In [5]: a[(idx := idx +1)]
      Out[5]: 1

      In [6]: a[(idx := idx +1)]
      Out[6]: 2
      '''

      Is this a bug or am I misreading the PEP-572 document somewhere? It's not a top-level assignment nor is it a list comprehension so I would expect it to work in the first example.

    2. Brando753
      added
      topic-asyncio
      3.8 (EOL)end of lifeend of life
      on Nov 10, 2020
    3. terryjreedy commented on Nov 14, 2020

      @terryjreedy
      terryjreedy
      on Nov 14, 2020
      Member
      More actions

      PEP-572 does not saw much of anything about when parens are needed. Nor does the low priority itself. Looking through the grammar of expressions, an assignment_expression is also a starred_expression, a positional_item (in calls), and the first part of a comprehension. It is not itself an plain expression unless and until wrapped in parentheses. Subscription requires an expression list, which may be a single expression.

      To put it another way: an expression is an assignment expression but an assignment expression with a "name :=" prefix is not an expression, so parens are required anywhere an expression is required. That includes subscripts, slicings, displays, call items other than positional items, comprehension parts other than the initial expression (maybe, check), parts of conditional expressions (maybe, check), and lambda expression bodies. After checking, I would like a sentence added to the doc before the 'go see the PEP' bit.

      This has nothing to do with asyncio.

    4. terryjreedy
      added
      docsDocumentation in the Doc dirDocumentation in the Doc dir
      interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
      3.10 (EOL)end of lifeend of life
      and removed
      topic-asyncio
      3.8 (EOL)end of lifeend of life
      on Nov 14, 2020
    5. terryjreedy
      assigned
      docspython
      on Nov 14, 2020
    6. terryjreedy
      added
      docsDocumentation in the Doc dirDocumentation in the Doc dir
      interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
      and removed
      topic-asyncio
      on Nov 14, 2020
    7. 2 remaining items

    8. terryjreedy
      assigned
      docspython
      on Nov 14, 2020
    9. lysnikolaou commented on Nov 16, 2020

      @lysnikolaou
      lysnikolaou
      on Nov 16, 2020
      Member
      More actions

      New changeset cae6018 by Lysandros Nikolaou in branch 'master':
      bpo-42316: Allow unparenthesized walrus operator in indexes (GH-23317)
      cae6018

    10. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    11. JelleZijlstra
      added a commit that references this issue on Oct 6, 2022

      gh-86482: Document assignment expression need for ()s (#23291)

      2b5f136
    12. miss-islington
      added 2 commits that reference this issue on Oct 6, 2022

      pythongh-86482: Document assignment expression need for ()s (pythonGH…

      cc41183

      pythongh-86482: Document assignment expression need for ()s (pythonGH…

      90ebcbc
    13. JelleZijlstra
      self-assigned this
      on Oct 6, 2022
    14. miss-islington
      added 2 commits that reference this issue on Oct 6, 2022

      gh-86482: Document assignment expression need for ()s (GH-23291)

      4aa2ebc

      gh-86482: Document assignment expression need for ()s (GH-23291)

      b7487df
    15. carljm
      added 2 commits that reference this issue on Oct 6, 2022

      Merge branch 'main' into dictwatch

      e5d2169

      Merge branch 'main' into typewatch

      415ed49
    16. mpage
      added a commit that references this issue on Oct 11, 2022

      pythongh-86482: Document assignment expression need for ()s (python#2…

      ff0d621
    17. pablogsal
      added a commit that references this issue on Oct 22, 2022

      gh-86482: Document assignment expression need for ()s (GH-23291)

      cc10a8e
    18. hauntsaninja commented on Oct 28, 2022

      @hauntsaninja
      hauntsaninja
      on Oct 28, 2022
      Contributor
      More actions

      Thanks, looks like we've completed this

    19. hauntsaninja
      closed this as completedon Oct 28, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @JelleZijlstra
      JelleZijlstra

    Labels

    3.10 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.