astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
31.34k stars 1.05k forks source link

Add new checks from flake8-errmsg #13491

Open wwuck opened 3 days ago

wwuck commented 3 days ago

I would like to request adding two new checks from flake8-errmsg that have been added since the original checks were added to ruff.

https://github.com/henryiii/flake8-errmsg/pull/23

Example test.py:

def foo():
    raise Exception

def bar():
    raise Exception()
test.py:2:5: EM104 Built-in Exceptions must not be thrown without being called
test.py:6:5: EM105 Built-in Exceptions must have a useful message
opk12 commented 3 days ago

Related: RSE102 Unnecessary parentheses on raised exception [unnecessary-paren-on-raise-exception]

MichaReiser commented 3 days ago

Related: RSE102 Unnecessary parentheses on raised exception [unnecessary-paren-on-raise-exception]

This is a great note. We would have to merge RSE102 and EM104 to avoid introducing conflicting rules, but that's difficult because RSE102 applies to all exceptions where EM104 applies only to built-in exceptions, unless we extend its scope. This needs some design and a decision.

opk12 commented 2 days ago

Newbie Q: is EM104 redundant with EM105 though?

opk12 commented 2 days ago

Also, what about checking for any stdlib exception, even if not a builtin in this sense? The original feature request argument (that is, ease of debugging and log file informativeness) applies if an exception has an unspecific name, or can be raised in very many places. I don't know if stdlib non-builtin exceptions do exist after PEP 3151, though.

MichaReiser commented 2 days ago

Newbie Q: is EM104 redundant with EM105 though?

I consider EM104 a less opinionated version of EM105. Having the rules separate allows some users to only opt in to the stylistic EM104 without requiring an exception message. But yes, the rule is redundant if both EM104 and EM105 are enabled. This is a great point.