Today I attempted this project: Why did I get a "SyntaxError: cannot assign to function call"?
I am an SME, so of course I do not have such a problem myself. There are over a hundred questions on Stack Overflow with a common proximate cause (trying to assign to the result of a function call, like the error message says).
Many of these questions can be categorized as typos, but it will often be the case that OP is too unskilled to recognize the typo or understand why the syntax is invalid. Even when it is clearly a typo, it is faster to dupehammer when a canonical duplicate is available, and apparently many people in the past did find such questions worthy of answers.
The problem for dupe-voters is that there is a wide variety of ultimate causes for the error: i.e. what OP was trying to accomplish. Each of these necessarily indicates a different explanation, because "don't write it like that" isn't helpful; the OP needs to figure out what should be written instead. However, these questions tend to have very non-descriptive titles. It's really, really hard to give them titles that make it obvious which ultimate cause is discussed; and even if this were somehow attempted, the search results would still be awful.
My thought was to gather the various questions, do a little cleanup, identify patterns in how people end up writing the code wrongly, and categorize them by ultimate cause.
For each cause, I could pick the best target, dupe-hammer the others, and then provide a listing that others could use as a reference to get the right canonicals (instead of having to read through dozens of questions that came up in the search box). For example, I noticed that a large number of these questions are really duplicates of How do I create variable variables? or similar; these ones are best addressed by ignoring the question about the SyntaxError
and directly engaging with OP's ill-conceived goal.
To make the question and answer separately useful, I ask some general questions about the error, as a framing device:
The error message in these cases is pretty self-explanatory: the code tries to assign to "a function call", and this is not allowed. But what does that actually mean? What can we assign to, and why is syntax like
foo() = 3
not valid? How can I figure out the right code to do what I want, depending on what the context (the actualfoo
function)?
For each cause, I give a brief summary (since the original Q&A pairs often have difficulty getting to the point, even after editing); I also try to answer the conceptual question about why such code is erroneous.
This effort does not appear to have been well received, or at least it is controversial. Have I done something wrong? How can I improve the question and answer? I had recently seen an excellent artificial duplicate by Peter Cordes on a different topic. I have a different problem to solve, but I had inferred that there is a fair bit of leeway on Stack Overflow when it comes to asking questions "artificially".