You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
An operator is missing in the list of tokens #99000
The documentation gives the list of tokens that are operators. The attribute reference operator (aka the dot operator) is missing in this list. Attribute reference is indeed an operator, it is the second in the order of precedence as indicated in the precedence table.
The dot so-called "operator" is not an actual operator, because it doesn't accept an arbitrary expression that evaluates to a value. The dot is a delimiter and anyone describing it as an operator is either mistaken or talking informally.
At the top of the first column of the precedence table, the documentation explicitly specifies operator, I don't think it uses this term informally. In the same column, the second row of the table gives x.attribute. So which operator do you think it is?
I do think they *are* using the term informally. The dot is *defined* by Python's grammar as a delimiter, not an operator.
Parentheses `( ... )` are also not an operator, and yet there they are, listed at the very top of the table.
And as I mentioned early, the dot is not an operator because the two "operands" are not values. The left side of the dot is an expression which evaluates to a value, but the right side is not. It is an identifier, not an expression:
(expression).name # legal
(expression).(mystring.lower().strip() + 'suffix') # Not legal.
If the dot was an operator, like `+` or `is` or the other operators, both sides of the dot would be expressions that evaluate to a value.
The dot so-called "operator" is not an actual operator
In my view, this is splitting hairs. The grammar is complex enough to where there isn't really a bright line distinguishing "delimiters" from "operators". That is an artificial distinction that isn't always useful. In a way, the dot is an operator but acts as a "special form". The expression goes to the left of the operator and the "special form" auto quotes the string the right.
From. a user point of view, it is perfectly reasonable to think of the dot as an operator. Just like + is associated with __add__, the dot is associated with __getattribute__. Add like the + operator, the . has a precedence. These two facts make it useful to think of the dot an operator. I think most people mentally model it that way. In books, blog posts and our own docs, we talk about the dot as an operator when it makes sense in contexts where the word "delimiter" would be confusing and lacking in explanatory value.
In summary, I think the OP's request is reasonable.
As a manner of speech, delimiters (also) acting like operators are very close to operators.
But the referred documentation section starts:
"Lexical analysis
A Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer. This chapter describes how the lexical analyzer breaks a file into tokens."
That's likely what needs the technical precision to sharply distinguish operators from delimiters.
Certainly the dot has to be put in the precedence table for the
same reason that parentheses used for grouping is in there.
But is it really "splitting hairs" to distinguish between delimiters
such as dot and actual operators? There is a fundamental and important
difference between the dot and operators: the term to the right of the
dot is not a value and does not take an expression as operand. If you
think that dot is an operator, it is reasonable to use an expression for
the right hand operand: `obj.("prefix" + word.lower())`. But you can't,
the term on the right isn't an operand, and the dot really isn't an
operator.
I don't think that it is splitting hairs to acknowledge that fact. We've
made that distinction for the entire history of Python, 30+ years. I
don't believe that was a mistake or confusing.
As for `@`, the reason that it appears in the operator table is because
it *actually is* an operator, the matrix multiplication operator.
Are the prefix '*' and '**' operators ? If yes, they should also be listed in the same precedence table.
At the top of the first column of the precedence table, the documentation explicitly specifies operator, I don't think it uses this term informally. In the same column, the second row of the table gives x.attribute. So which operator do you think it is?
Activity
stevendaprano commentedon Nov 2, 2022
The dot so-called "operator" is not an actual operator, because it doesn't accept an arbitrary expression that evaluates to a value. The dot is a delimiter and anyone describing it as an operator is either mistaken or talking informally.
Pascal-Ortiz commentedon Nov 2, 2022
At the top of the first column of the precedence table, the documentation explicitly specifies operator, I don't think it uses this term informally. In the same column, the second row of the table gives
x.attribute. So which operator do you think it is?stevendaprano commentedon Nov 2, 2022
rhettinger commentedon Nov 2, 2022
In my view, this is splitting hairs. The grammar is complex enough to where there isn't really a bright line distinguishing "delimiters" from "operators". That is an artificial distinction that isn't always useful. In a way, the dot is an operator but acts as a "special form". The expression goes to the left of the operator and the "special form" auto quotes the string the right.
From. a user point of view, it is perfectly reasonable to think of the dot as an operator. Just like
+is associated with__add__, the dot is associated with__getattribute__. Add like the+operator, the.has a precedence. These two facts make it useful to think of the dot an operator. I think most people mentally model it that way. In books, blog posts and our own docs, we talk about the dot as an operator when it makes sense in contexts where the word "delimiter" would be confusing and lacking in explanatory value.In summary, I think the OP's request is reasonable.
rhettinger commentedon Nov 2, 2022
One other thought: The operator and delimiter tables already reflect some of the ambiguity between an operator and delimiter:
Technically, this is also true for
[]which calls__getitem__and()which invokes__call__in some contexts but not others.The
@token in listed in both the operator table and delimiter table. ISTM the dot warrants the same treatment.Dutcho commentedon Nov 2, 2022
I understand both views.
As a manner of speech, delimiters (also) acting like operators are very close to operators.
But the referred documentation section starts:
"Lexical analysis
A Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer. This chapter describes how the lexical analyzer breaks a file into tokens."
That's likely what needs the technical precision to sharply distinguish operators from delimiters.
stevendaprano commentedon Nov 3, 2022
jidhub commentedon Oct 18, 2024
Are the prefix '*' and '**' operators ? If yes, they should also be listed in the same precedence table.
StanFromIreland commentedon Aug 17, 2025
cc @encukou, should this just be closed as a duplicate of the meta issue? (#137713)