Skip to content

precedence rules for ternary operator #52287

Description

@djc
BPO 8039
Nosy @birkenfeld, @ericvsmith, @djc, @ezio-melotti, @meadori
Files
  • issue-8039.patch: patch against 2.7 trunk
  • 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/birkenfeld'
    closed_at = <Date 2010-03-07.21:13:23.467>
    created_at = <Date 2010-03-02.14:26:03.896>
    labels = ['docs']
    title = 'precedence rules for ternary operator'
    updated_at = <Date 2010-03-07.21:13:23.465>
    user = 'https://github.com/djc'

    bugs.python.org fields:

    activity = <Date 2010-03-07.21:13:23.465>
    actor = 'georg.brandl'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2010-03-07.21:13:23.467>
    closer = 'georg.brandl'
    components = ['Documentation']
    creation = <Date 2010-03-02.14:26:03.896>
    creator = 'djc'
    dependencies = []
    files = ['16477']
    hgrepos = []
    issue_num = 8039
    keywords = ['patch']
    message_count = 4.0
    messages = ['100294', '100341', '100562', '100611']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'eric.smith', 'djc', 'ezio.melotti', 'meador.inge']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue8039'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7']

    Activity

    1. djc commented on Mar 2, 2010

      @djc
      ContributorAuthor

      So http://docs.python.org/reference/expressions.html doesn't currently mention the ternary operator as far as I can see. Maybe this is trivial, but it would be nice to know where it fits into the hierarchy.

      (I.e., my co-worker just came up to me asking when he needed the parentheses around the entire expression and when he didn't, and I couldn't give him a good answer.)

    2. added
      docsDocumentation in the Doc dir
      on Mar 2, 2010
    3. ericvsmith commented on Mar 3, 2010

      @ericvsmith
      Member

      For what it's worth, these are properly called "Conditional Expressions". See PEP-308 for the gory details, including figuring out what the precedence is. It was news to me that the allowed syntax is slightly different in 2.x and 3.x.

    4. meadori commented on Mar 7, 2010

      @meadori
      Member

      It seems to me from the grammar (http://docs.python.org/reference/expressions.html#grammar-token-conditional_expression) that the precedence for conditional expressions fall in between that of 'lambda' and 'or' expressions.

    5. birkenfeld commented on Mar 7, 2010

      @birkenfeld
      Member

      if-else actually was already documented, under "boolean expressions". It was merely missing from the precendence table.

      I've now given it its own section, to make it stand out a bit better. See r78772.

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

    docsDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions