Skip to content
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

Disable too-few-public-methods for attrs. #2988

Closed
benjamin-kirkbride opened this issue Jun 30, 2019 · 2 comments
Closed

Disable too-few-public-methods for attrs. #2988

benjamin-kirkbride opened this issue Jun 30, 2019 · 2 comments

Comments

@benjamin-kirkbride
Copy link

Is your feature request related to a problem? Please describe

Dataclasses, and some similar types of classes disable the too-few-public-methods check, but attrs does not. In addition there is not any way to specify types of classes to automatically ignored for those types of checks.

Describe the solution you'd like

Attrs should probably by default disable too-few-public-methods.

Another potential option is to allow the user to specify decorators in the pylintcr that should disable certain checks.

Additional context

I def could just be dumb and unaware of the solution to this problem, but I did google around a lot, and read through design_analysis.py to no avail.

@PCManticore
Copy link
Contributor

Hey @Beefy-Swain Thanks for the report, this now should be fixed in master.

@xqgex
Copy link

xqgex commented Apr 27, 2023

The error still exists with pylint version 2.17.0 and attrs version 23.1.0

Code:

""" Module description. """

from attrs import define, field, frozen
from attrs.validators import instance_of


@define
class Bar:
    """ Class description. """
    field: int = field(validator=instance_of(int))


@frozen
class Foo:
    """ Class description. """
    field: int = field(validator=instance_of(int))


print(Bar(5))
print(Foo(7))

Output:

************* Module test
test.py:8:0: R0903: Too few public methods (0/2) (too-few-public-methods)
test.py:14:0: R0903: Too few public methods (0/2) (too-few-public-methods)

------------------------------------------------------------------
Your code has been rated at 7.50/10

akirchhoff-modular added a commit to akirchhoff-modular/pylint that referenced this issue Jan 4, 2024
Beginning with attrs 21.1.0, the recommended way to use attrs is through
`import attrs` and using `attrs.define`/`attrs.frozen`, not `import
attr` and `attr.s` or `attr.attrs`. Pylint does understand `attr.attrs`
(pylint-dev#2988), but new-style uses of attrs are not understood to be data class
decorators.

Modify `_is_exempt_from_public_methods` to recognize `attrs.define` and
`attrs.frozen` in a similar way as is currently done with
`dataclasses.dataclass`.

Closes pylint-dev#9345.
jacobtylerwalls pushed a commit that referenced this issue May 4, 2024
…9346)

Beginning with attrs 21.1.0, the recommended way to use attrs is through
`import attrs` and using `attrs.define`/`attrs.frozen`, not `import
attr` and `attr.s` or `attr.attrs`. Pylint does understand `attr.attrs`
(#2988), but new-style uses of attrs are not understood to be data class
decorators.

Modify `_is_exempt_from_public_methods` to recognize `attrs.define` and
`attrs.frozen` in a similar way as is currently done with
`dataclasses.dataclass`.

Closes #9345.
github-actions bot pushed a commit that referenced this issue May 4, 2024
…9346)

Beginning with attrs 21.1.0, the recommended way to use attrs is through
`import attrs` and using `attrs.define`/`attrs.frozen`, not `import
attr` and `attr.s` or `attr.attrs`. Pylint does understand `attr.attrs`
(#2988), but new-style uses of attrs are not understood to be data class
decorators.

Modify `_is_exempt_from_public_methods` to recognize `attrs.define` and
`attrs.frozen` in a similar way as is currently done with
`dataclasses.dataclass`.

Closes #9345.

(cherry picked from commit c032181)
jacobtylerwalls pushed a commit that referenced this issue May 4, 2024
…9346) (#9596)

Beginning with attrs 21.1.0, the recommended way to use attrs is through
`import attrs` and using `attrs.define`/`attrs.frozen`, not `import
attr` and `attr.s` or `attr.attrs`. Pylint does understand `attr.attrs`
(#2988), but new-style uses of attrs are not understood to be data class
decorators.

Modify `_is_exempt_from_public_methods` to recognize `attrs.define` and
`attrs.frozen` in a similar way as is currently done with
`dataclasses.dataclass`.

Closes #9345.

(cherry picked from commit c032181)

Co-authored-by: akirchhoff-modular <[email protected]>
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

3 participants