Skip to content

Pylint reports false positives on exception classes with custom init #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zhiltsov-max opened this issue Feb 1, 2022 · 2 comments
Closed

Comments

@zhiltsov-max
Copy link

zhiltsov-max commented Feb 1, 2022

from attrs import define, field

@define(auto_exc=False, init=False)
class BaseError(Exception):
    v: int = field(default=0, kw_only=True)

    def __init__(self, msg=None, *, v=None):
        super().__init__(msg)
        self.__attrs_init__(v=v or 0)

# Pylint will raise false positive warnings for derived classes,
# when __init__ is defined directly. Monkey-patching resolves the problem:
# setattr(BaseError, '__init__', BaseError._my__init__)

@define(auto_exc=False)
class Error1(BaseError):
    x: int
    y: int

print(Error1(1, 2)) # << here

pylint pylint_example.py
************* Module pylint_example
pylint_example.py:20:6: E1121: Too many positional arguments for constructor call (too-many-function-args)

Attrs 21.4.0, pylint 2.10.2. But it happened in earlier versions too.

@hynek
Copy link
Member

hynek commented Feb 2, 2022

That sounds like something that should be brought up on the pylint bug tracker and not here?

@zhiltsov-max
Copy link
Author

zhiltsov-max commented Feb 2, 2022

Ok, if you say so.

upd: it looks, there are some reports about attrs support: pylint-dev/pylint#3492 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants