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

Setter by property: false positive warning #24

Open
vepain opened this issue Jul 8, 2021 · 2 comments
Open

Setter by property: false positive warning #24

vepain opened this issue Jul 8, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@vepain
Copy link

vepain commented Jul 8, 2021

False positive description

class Foo:

  __ACLASSATTR = 0

  def __init__(n: int):
    self.__n = n

  @property
  def n(self):
    """The n getter."""
    return self.__n

  @n.setter
  def n(self, new_n: int):
    """The n setter befor @classmethod creates a warning."""
    self.__n = new_n

  @classmethod
  def a_classattr(cls):
    return cls.__ACLASSATTR

Behavior

What expected (to my mind)

no warning

Current result

Foo.n should be after Foo.a_classattr

Discussion

Because of the false positive result of mypy (see python/mypy#1465) the two warnings make the problem unfeasible.
But I think it is a great idea to keep getter and setter near to each other for the same attribute.
So let consider you have to keep setter just after the getter

Versions

  • Python: 3.9.5
  • flake8: 3.9.0
  • flake8-class-attributes-order: 0.1.2

Thank you for your work!

@vepain vepain added the bug Something isn't working label Jul 8, 2021
@aktentasche
Copy link

I second this bug, my minimum working example is:

class LogMessage:
    @property
    def package(self) -> str:
        return ""

    @package.setter
    def package(self, value: str) -> None:
        self.bar = value

    @property
    def message(self) -> str:
        return ""

    @message.setter
    def message(self, value: str) -> None:
        self.foo = value

When I group the setters the error goes away.

@Mogost
Copy link

Mogost commented Jun 27, 2022

Also faced this. Seems very reasonable to keep property and setter together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants