Python Analyzer feedback for W0707 contains conflicting quotes

When raising an exception in an except block without as/from, the Python Analyzer gives feedback with inline code that is surrounded by single quotes instead of backticks:

Analyzer Feedback

Line 23 [W0707 raise-missing-from] was reported by Pylint:

Consider explicitly re-raising using ‘except Exception as exc’ and ‘raise ValueError('syntax error') from exc’.

There is an issue in the code that could lead to a bug or error in the program. While this error might not be severe, it could lead to more severe issues in the future. It is recommended the problem be addressed before proceeding further.

Instead of:

try:
    1 / 0
except ZeroDivisionError as e:
    raise ValueError("Rectangle Area cannot be zero")  # [raise-missing-from]

Try:

try:
    1 / 0
except ZeroDivisionError as e:
    raise ValueError("Rectangle Area cannot be zero") from e

This is especially confusing in this case, as the code also has single quotes in it.

Thanks for this. :smile: Look for a fix sometime today (once I get the concept typos nailed).

1 Like

Sadly, I cannot get those single quotes corrected. They are part of the core rule message that PyLint emits, so I’d have to re-create the rule to override the message. :slightly_frowning_face:

This will have to go on the “someday” list, along with changes to the invalid-names rule rewrite.

It’s just not going to happen very quickly. Apologies.

2 Likes

It’s fine, I understand that there are probably plenty of things that have a higher time-to-benefit ratio than this, due to having to rewrite the Pylint rule.