Pablo Galindo Salgado <[email protected]> added the comment:
I agree this is weird, but technically is not incorrect. For example, consider
this:
>>> def foo(f):
... return f
...
>>> @x = foo
File "<stdin>", line 1
@x = foo
^^^^^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
but with ':=' it works:
>>> @x := foo
... def g():
... ...
...
Same for using '==' (although much work):
>>> def foo(f):
... return f
...
>>> class A:
... def __eq__(self, other):
... return foo
...
>>> @A() = A()
File "<stdin>", line 1
@A() = A()
^^^
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead
of '='?
But it works with '==':
>>> @A() == A()
... def g():
... ...
...
>>> g
<function g at 0x10d4f3c20>
This shows two things:
* Is technically syntactically valid, but semantically invalid. Notice that the
suggestion is not false: the parser tells you that if you use '==' or ':=' it
won't be a SyntaxError, and that is true.
* There are ridiculous cases when this can succeed, and actually some where it
does even make sense (':=').
I am therefore closing this as 'not a bug', but please, feel free to comment
back if you disagree :)
----------
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45807>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com