Skip to content

[new rule] suggesting raise Exception over raise Exception() when no args #8318

Open
@jamesbraza

Description

@jamesbraza

Current problem

Please see the below code:

# pylint: disable=missing-module-docstring,missing-function-docstring

from typing import NoReturn

def way_one() -> NoReturn:
    raise ValueError  # C code instantiation of ValueError

def way_two() -> NoReturn:
    raise ValueError()  # Interpreter instantiation of ValueError (slower)

Check this Stack Overflow answer: https://stackoverflow.com/a/16709222

way_one is faster than way_two, when not specifying arguments to the Exception class.

Desired solution

I think it would be cool if pylint would suggest this minor optimization, when no arguments are specified.

Something like consider-raising-with-class:

> pylint a.py
a.py:9: W1234: Consider raising with exception class if no message (consider-raising-with-class)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement ✨Improvement to a componentMinor 💅Polishing pylint is always niceNeeds decision 🔒Needs a decision before implemention or rejection

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions