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
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.
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.
skrah commented on Nov 12, 2018
skrahmannequin
Mannequin
More actions
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.
Activity
pablogsal commentedon Nov 10, 2018
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.
pablogsal commentedon Nov 10, 2018
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 :)
gvanrossum commentedon Nov 10, 2018
I could have sworn Benjamin showed a fix for this during the core-dev sprint in Seattle...
serhiy-storchaka commentedon Nov 10, 2018
Actually,
(a) = 42doesn'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.
gvanrossum commentedon Nov 10, 2018
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.
skrah commentedon Nov 12, 2018
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.
gvanrossum commentedon Nov 12, 2018
Let's close this already. It won't happen. Sorry for the noise.