Mypy: Property setter not accepted if not next to getter

Created on 2 May 2016  路  5Comments  路  Source: python/mypy

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.

bug false-positive priority-1-normal

Most helpful comment

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.

All 5 comments

1713 has another example and some ideas.

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

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

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Stiivi picture Stiivi  路  3Comments

arquolo picture arquolo  路  3Comments

takeda picture takeda  路  3Comments

yupeng0921 picture yupeng0921  路  3Comments

JukkaL picture JukkaL  路  4Comments