Skip to content

Disallow expressions like (a) = 42 #79388

Closed

Description

@pablogsal
BPO 35207
Nosy @gvanrossum, @mdickinson, @benjaminp, @skrah, @serhiy-storchaka, @pablogsal
PRs
  • bpo-35207: Disallow expressions like (a) = 42 #10444
  • 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 = 'https://github.com/pablogsal'
    closed_at = <Date 2018-11-12.21:35:48.684>
    created_at = <Date 2018-11-10.04:13:18.571>
    labels = ['interpreter-core', 'invalid', '3.8']
    title = 'Disallow expressions like (a) = 42'
    updated_at = <Date 2018-11-12.21:35:48.683>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2018-11-12.21:35:48.683>
    actor = 'pablogsal'
    assignee = 'pablogsal'
    closed = True
    closed_date = <Date 2018-11-12.21:35:48.684>
    closer = 'pablogsal'
    components = ['Interpreter Core']
    creation = <Date 2018-11-10.04:13:18.571>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35207
    keywords = ['patch']
    message_count = 7.0
    messages = ['329590', '329591', '329593', '329596', '329644', '329731', '329740']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'mark.dickinson', 'benjamin.peterson', 'skrah', 'serhiy.storchaka', 'pablogsal']
    pr_nums = ['10444']
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue35207'
    versions = ['Python 3.8']

    Activity

    1. pablogsal commented on Nov 10, 2018

      @pablogsal
      MemberAuthor

      As commented on bpo-33878, the fact that expressions like (x) = 42 are accepted is, in reality, an implementation detail and they should be disallowed.

    2. self-assigned this
      on Nov 10, 2018
    3. pablogsal commented on Nov 10, 2018

      @pablogsal
      MemberAuthor

      I am not sure if this is the cleanest/simplest implementation...if you think there is a better way to do this I am happy to change the Pull Request :)

    4. gvanrossum commented on Nov 10, 2018

      @gvanrossum
      Member

      I could have sworn Benjamin showed a fix for this during the core-dev sprint in Seattle...

    5. serhiy-storchaka commented on Nov 10, 2018

      @serhiy-storchaka
      Member

      Actually, (a) = 42 doesn't contradict the grammar.

      assignment_stmt ::= (target_list "=")+ (starred_expression | yield_expression)
      target_list ::= target ("," target)* [","]
      target ::= identifier
      | "(" [target_list] ")"
      | "[" [target_list] "]"
      | attributeref
      | subscription
      | slicing
      | "*" target

      So that if we decide to disallow such things, we should change the definition in the language reference.

      I thought the code should be similar to the code added in bpo-34641. But maybe there is a way to simplify both code.

    6. gvanrossum commented on Nov 10, 2018

      @gvanrossum
      Member

      Hm, I was thinking of #9212, but
      that's about keyword arg (where the interpreter incorrectly allowed
      f((kw)=expr). But on thinking about it more I believe we should allow (a) =
      (b), so there is no code change required. Sorry for the false alarm.

    7. skrah commented on Nov 12, 2018

      skrahmannequin
      Mannequin

      I just want to add one more voice for allowing the status quo:

      C, OCaml, SML, Haskell allow the assignment, Ruby disallows it.

      The ML family must allow it, since "let (x) = 10" is pattern matching
      under the hood, and (10) = 10.

      In C (gcc, clang at least, I didn't check the standard) it may be convenience.

      Python's assignment unpacking is similar to pattern matching, so
      while the construct is surprising at first, I think it's the right
      thing to do.

    8. gvanrossum commented on Nov 12, 2018

      @gvanrossum
      Member

      Let's close this already. It won't happen. Sorry for the noise.

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.8 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions