In C++, you sometimes have a situation where assigning to a function call makes sense--my understanding is that this is permissible when the function call returns an lvalue. So you might have:
some_function() = some_value;
In Python, it's not quite the same. Based on my understanding of the language, I would assume that there's never a time to assign to a function call. Yet if you try, you get a somewhat cryptic error message that suggests it may be possible. Here's a fairly minimal example (run with Python 3.10.8 and IPython 8.6.0):
In [1]: enumerate() = x
Cell In [1], line 1
enumerate() = x
^
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
Because it says, "cannot assign to function call here", it seems implied there are cases where you might.
I'm wondering why that error message is as it is. Should it really say, "cannot assign to function call (at all)"? I expect this is the case, but I'm curious if there's some esoteric/special case that the error message is referencing when it says, "cannot assign to function call here".
I've tried searching this but can only find questions for people trying to resolve this error, for instance this question. To be clear, I am not trying to resolve this error; I understand what's wrong (and there are quite a few things wrong) with enumerate() = x
. I'm merely curious why IPython makes it sound like there may be some situation where it is appropriate syntax to say some_function() = some_value
.
Is there something, or is it as I expect that this is just a confusingly written error message? Perhaps it just means "here" is the line/column where the error is? You'd think the arrow/carrot ^ pointing to it would be sufficient were that the case.