Skip to content

When raising NotImplementedError , ARG002 and EM101 are incompatible. #12427

@DaniBodor

Description

@DaniBodor

ARG002 is usually not raised in methods that immediately raise a NotImplementedError, but does if there is some other code in the method. However, EM101 enforces adding the error message into a separate variable, which is then seen as "code".

The result of this is that there is no way to write such a method without raising one or the other issue. See example below.

class EM101_found:
    def test_method(self, **kwargs):
        raise NotImplementedError("error message.")


class ARG002_found:
    def test_method(self, **kwargs):
        msg = "error message"
        raise NotImplementedError(msg)

running ruff check test_file.py --select ARG002 --select EM101 on the code snippet above results in

test_file.py:3:35: EM101 Exception must not use a string literal, assign to variable first
test_file.py:7:29: ARG002 Unused method argument: kwargs
Found 2 errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions