Not focusing too closely on the specific example, let's look a little broader.
It's a meme here that people will write "you should use jQuery" answers so I hope that points out the broader problem with many of the answers here saying it's OK to ignore constraints. Many things we do set constraints and those can be anything from the language being used to specifications like in this example.
Answers that ignore these limitations are at risk of failing to answer the question. If someone asks how to do something in Python and they get an answer for Perl - I think y'all would all agree that's not an answer. Sure, someone may happen on the question and be looking for an answer about Perl - but that's kinda a silly expectation.
Instead, we have a question about the issue in Perl and a question about Python and visitors get targeted and helpful answers in their language without having to dig through answers to the same question in dozens of other languages on the same post.
So, I would caution y'all from saying "it's fine to ignore restraints, the answer is still correct"... because the important thing is that answers answer the question that's asked. If we want the same question without constraints, we can do that but we shouldn't be shoehorning in an answer that ignores constraints.
Exception(s)
So, there's a couple exceptions to this that I feel are worth bringing up and there are likely others but the key in both is that the answer needs to recognize the question and the constraints and explain why it's necessary to do it another way.
It's just not possible.
The first is in situations where what the asker wants just isn't possible.
You want to do this without _____ but, given the information you've provided, that doesn't seem possible because ______. Instead, you'll need to do ______ and that will solve your problem so that you can get going again.
Sure, proving a negative isn't always possible but it's a good place to start. You can always hedge by saying "as far as I'm aware, what you're asking isn't possible".
It's not safe/secure.
Doing something the way the asker wishes is possible but would be a bad practice - it's a security risk, it's leaky, or there's just something about constraints that would cause stuff to break... whatever. The point is, if the asker used the solution they want, it's possible but a terrible choice.
In this situation, you can choose to answer the question or not but the focus should be explaining on why the asker (and future readers) should avoid the solution required by the constraints. Then, provide the standard, safe, recommended solution.
Again, as with the former, it's best to make sure to recognize the constraints from the question so that it's clear to others that you're not just ignoring them and you're providing the best solution you can.
In both of these cases, you're doing a lot to really help people understand and grow as programmers - you're not just rotely answering a question, you're helping others to understand why a solution is good or necessary. The "Why" is so important! It can help people retain the solution and better understand the language they're using and avoid similar issues in the future.
For cases where an answer fails to do one of the above... that's kinda a hard call. Here on SO y'all have a different definition of what makes an answer than many sites on the network for a variety of historical reasons. When I use or handle NAA flags, I am specifically asking "Does this answer the question as asked?" but I'm aware the default on SO is often more along the lines of "Does this answer a question?" This disagreement can be seen in the two opposing answers on the MSE FAQ about NAA flags.
According to the top answer, I shouldn't use an NAA flag but this answer ignores many other possible issues with answers that the second answer attempts to address, including answers that are answering another question altogether:
- answers that attempt to answer another question or are just a general dump of unsolicited information, for example:
Question: What is the capital of Brazil?
Not an answer 1: The capital of Argentina is Buenos Aires.
Not an answer 2: Brazil is a state in South America.
Not an answer 3: We went to Brazil for our honeymoon.
Now, these examples are pretty blatant but I feel like answers that ignore the constraints of the question fall into the same category. Something more like:
Question: What color, other than blue is mixed to make green.
Not an answer: Blue is one of the colors mixed to make green.
So, I've not learned anything new in this answer - I already knew blue was one of the colors! I need an answer that tells me "yellow". So, would you delete this answer that says "Blue"? I'd probably call it NAA and leave a comment pointing out the issue to the user, yeah. I know comments can be somewhat stressful but they're really useful for reviewers and mods to see why something may have been flagged as NAA.
The question already seems aware of blue as an answer to this but is looking for something different. Can you elaborate on why blue is the correct answer or adjust your answer to include the information the question is asking for?
And someone did leave such a comment on the answer outlined in the question here, which is great.
Anyway, my recommendation for SO would be to leave a comment like the one immediately above pointing out that the answer might have missed part of the question and encouraging the answer to recognize the limitations of the question and explain why their solution is necessary rather than a solution that would work within the limitations. It's completely possible that the answer is merely incomplete and just needs some additional detail but a comment is the best way to achieve that.
How you want to decide on the flagging issue... I'd recommend that y'all rethink how you view NAAs and why the definition is so narrow here and whether not flagging something that fails to take the entire question into account is the best course of action.