This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pablogsal
Recipients aroberge, lys.nikolaou, pablogsal, quentel, schmave
Date 2021-11-16.09:23:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1637054604.2.0.375560124515.issue45807@roundup.psfhosted.org>
In-reply-to
Content
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 :)
History
Date User Action Args
2021-11-16 09:23:24pablogsalsetrecipients: + pablogsal, aroberge, quentel, lys.nikolaou, schmave
2021-11-16 09:23:24pablogsalsetmessageid: <1637054604.2.0.375560124515.issue45807@roundup.psfhosted.org>
2021-11-16 09:23:24pablogsallinkissue45807 messages
2021-11-16 09:23:23pablogsalcreate