Skip to content

Property setter not accepted if not next to getter #1465

Description

@mihneagiurgea

The following code incorrectly raises an error:

class Config(object):

    @property
    def my_proprty(self):
        return None

    def _other(self):
        pass

    @my_proprty.setter
    def my_proprty(self, val):
        pass

Error:

mypytest.py: note: In class "Config":
mypytest.py:12: error: Callable[[Any], Any] has no attribute "setter"

Commenting out the _other method will fix the error.

Activity

  1. ilevkivskyi commented on Jun 4, 2017

    @ilevkivskyi
    Member

    #1713 has another example and some ideas.

  2. levsa commented on Aug 30, 2017

    @levsa

    What is the status of this issue? #1713 is closed as duplicate of this issue.

  3. JukkaL commented on Aug 30, 2017

    @JukkaL
    Collaborator

    We don't have immediate plans for fix this issue, but we are happy to receive a PR.

  4. changed the title [-]Wrong error for @smth.setter property[/-] [+]Property setter not accepted if not next to getter[/+] on Aug 30, 2017
  5. levsa commented on Aug 30, 2017

    @levsa

    I had missed that moving the setter next to getter solves the problem, which is good enough. Thanks for the update!

  6. 30 remaining items

  7. samskiter commented on May 27, 2023

    @samskiter

    This also affects subclasses that override properties, e.g.:

    class Parent(object):
        @property
        def foo(self):
            return "parent_foo"
    
    class Child(Parent):
        @Parent.foo.getter
        def foo(self):
            return "child_foo"

    mypy returns a "Callable[[Any], Any]" has no attribute "getter" error here. In this case, it's obviously not possible to move the two methods to be next to each other.

    Thanks for posting this - also struggling with this. Is there any known workaround? Specifically I wanted to override a property setter.

  8. asarkar commented on Sep 23, 2023

    @asarkar

    "No attribute" along with "Untyped decorator" error.

    class Cell(ABC):
        def __init__(self, value: int | None = None):
            ...
    
        @property
        def value(self) -> int | None:
            return self._value
    
    class InputCell(Cell):
        @Cell.value.setter
        def value(self, value: int) -> None:
        	...
    

    Running mypy with --strict generates:

    react.py:28: error: "Callable[[Cell], int | None]" has no attribute "setter"  [attr-defined]
    react.py:28: error: Untyped decorator makes function "value" untyped  [misc]
    

    Line 28 happens to be the @Cell.value.setter.

  9. added a commit that references this issue on Jun 26, 2024
  10. added a commit that references this issue on Jun 26, 2024
  11. added a commit that references this issue on Jul 28, 2024
  12. added a commit that references this issue on Mar 5, 2026
    a2fd9c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions