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

Property setter not accepted if not next to getter #1465

Open
mihneagiurgea opened this issue May 2, 2016 · 10 comments
Open

Property setter not accepted if not next to getter #1465

mihneagiurgea opened this issue May 2, 2016 · 10 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-descriptors Properties, class vs. instance attributes

Comments

@mihneagiurgea
Copy link

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.

@gvanrossum gvanrossum added the bug mypy got something wrong label May 2, 2016
cortesi added a commit to cortesi/mitmproxy that referenced this issue Mar 16, 2017
We get little benefit from our mypy QA checks at the moment, because we skip
imports. This patch is what's needed to make mypy succeed with imports on a
single file: master.py

It also updates mypy to the current version, and enables a QA check.

Mypy bugs I encountered:

dict.update with kwargs not supported:

python/mypy#1031

property setters and getters must be adjacent:

python/mypy#1465
cortesi added a commit to cortesi/mitmproxy that referenced this issue Mar 16, 2017
We get little benefit from our mypy QA checks at the moment, because we skip
imports. This patch is what's needed to make mypy succeed with imports on a
single file: master.py

It also updates mypy to the current version, and enables a QA check.

Mypy bugs I encountered:

dict.update with kwargs not supported:

python/mypy#1031

property setters and getters must be adjacent:

python/mypy#1465
cortesi added a commit to cortesi/mitmproxy that referenced this issue Mar 16, 2017
We get little benefit from our mypy QA checks at the moment, because we skip
imports. This patch is what's needed to make mypy succeed with imports on a
single file: master.py

It also updates mypy to the current version, and enables a QA check.

Mypy bugs I encountered:

dict.update with kwargs not supported:

python/mypy#1031

property setters and getters must be adjacent:

python/mypy#1465
cortesi added a commit to cortesi/mitmproxy that referenced this issue Mar 16, 2017
We get little benefit from our mypy QA checks at the moment, because we skip
imports. This patch is what's needed to make mypy succeed with imports on a
single file: master.py

It also updates mypy to the current version, and enables a QA check.

Mypy bugs I encountered:

dict.update with kwargs not supported:

python/mypy#1031

property setters and getters must be adjacent:

python/mypy#1465
cortesi added a commit to cortesi/mitmproxy that referenced this issue Mar 16, 2017
We get little benefit from our mypy QA checks at the moment, because we skip
imports. This patch is what's needed to make mypy succeed with imports on a
single file: master.py

It also updates mypy to the current version, and enables a QA check.

Mypy bugs I encountered:

dict.update with kwargs not supported:

python/mypy#1031

property setters and getters must be adjacent:

python/mypy#1465
cortesi added a commit to cortesi/mitmproxy that referenced this issue Mar 16, 2017
We get little benefit from our mypy QA checks at the moment, because we skip
imports. This patch is what's needed to make mypy succeed with imports on a
single file: master.py

It also updates mypy to the current version, and enables a QA check.

Mypy bugs I encountered:

dict.update with kwargs not supported:

python/mypy#1031

property setters and getters must be adjacent:

python/mypy#1465
cortesi added a commit to cortesi/mitmproxy that referenced this issue Mar 16, 2017
We get little benefit from our mypy QA checks at the moment, because we skip
imports. This patch is what's needed to make mypy succeed with imports on a
single file: master.py

It also updates mypy to the current version, and enables a QA check.

Mypy bugs I encountered:

dict.update with kwargs not supported:

python/mypy#1031

property setters and getters must be adjacent:

python/mypy#1465
cortesi added a commit to cortesi/mitmproxy that referenced this issue Mar 18, 2017
We get little benefit from our mypy QA checks at the moment, because we skip
imports. This patch is what's needed to make mypy succeed with imports on a
single file: master.py

It also updates mypy to the current version, and enables a QA check.

Mypy bugs I encountered:

dict.update with kwargs not supported:

python/mypy#1031

property setters and getters must be adjacent:

python/mypy#1465
@ilevkivskyi
Copy link
Member

#1713 has another example and some ideas.

@levsa
Copy link

levsa commented Aug 30, 2017

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

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 30, 2017

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

@JukkaL JukkaL changed the title Wrong error for @smth.setter property Property setter not accepted if not next to getter Aug 30, 2017
@levsa
Copy link

levsa commented Aug 30, 2017

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

@dacut
Copy link

dacut commented Apr 27, 2018

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.

CZNIC-GitLab pushed a commit to CZ-NIC/deckard that referenced this issue Oct 25, 2018
@JukkaL JukkaL added the false-positive mypy gave an error on correct code label Jul 26, 2019
mgfritch added a commit to mgfritch/ceph that referenced this issue Mar 2, 2020
workaround for mypy issue:
python/mypy#1465

fixes mypy errors:

volumes/fs/operations/group.py: note: In class "Group":
volumes/fs/operations/group.py:44: error: Name 'uid' already defined on line 36
volumes/fs/operations/group.py:44: error: "Callable[[Group], Any]" has no attribute "setter"
volumes/fs/operations/group.py:48: error: Name 'gid' already defined on line 40
volumes/fs/operations/group.py:48: error: "Callable[[Group], Any]" has no attribute "setter"

volumes/fs/operations/group.py: note: In function "open_group":
volumes/fs/operations/group.py:170: error: Property "uid" defined in "Group" is read-only
volumes/fs/operations/group.py:171: error: Property "gid" defined in "Group" is read-only

volumes/fs/operations/versions/subvolume_base.py: note: In class "SubvolumeBase":
volumes/fs/operations/versions/subvolume_base.py:45: error: Name 'uid' already defined on line 33
volumes/fs/operations/versions/subvolume_base.py:45: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:49: error: Name 'gid' already defined on line 37
volumes/fs/operations/versions/subvolume_base.py:49: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:53: error: Name 'mode' already defined on line 41
volumes/fs/operations/versions/subvolume_base.py:53: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"

Signed-off-by: Michael Fritch <[email protected]>
mgfritch added a commit to mgfritch/ceph that referenced this issue Mar 2, 2020
workaround for mypy issue:
python/mypy#1465

fixes mypy errors:

volumes/fs/operations/group.py: note: In class "Group":
volumes/fs/operations/group.py:44: error: Name 'uid' already defined on line 36
volumes/fs/operations/group.py:44: error: "Callable[[Group], Any]" has no attribute "setter"
volumes/fs/operations/group.py:48: error: Name 'gid' already defined on line 40
volumes/fs/operations/group.py:48: error: "Callable[[Group], Any]" has no attribute "setter"

volumes/fs/operations/group.py: note: In function "open_group":
volumes/fs/operations/group.py:170: error: Property "uid" defined in "Group" is read-only
volumes/fs/operations/group.py:171: error: Property "gid" defined in "Group" is read-only

volumes/fs/operations/versions/subvolume_base.py: note: In class "SubvolumeBase":
volumes/fs/operations/versions/subvolume_base.py:45: error: Name 'uid' already defined on line 33
volumes/fs/operations/versions/subvolume_base.py:45: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:49: error: Name 'gid' already defined on line 37
volumes/fs/operations/versions/subvolume_base.py:49: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:53: error: Name 'mode' already defined on line 41
volumes/fs/operations/versions/subvolume_base.py:53: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"

Signed-off-by: Michael Fritch <[email protected]>
mgfritch added a commit to mgfritch/ceph that referenced this issue Mar 2, 2020
workaround for mypy issue:
python/mypy#1465

fixes mypy errors:

volumes/fs/operations/group.py: note: In class "Group":
volumes/fs/operations/group.py:44: error: Name 'uid' already defined on line 36
volumes/fs/operations/group.py:44: error: "Callable[[Group], Any]" has no attribute "setter"
volumes/fs/operations/group.py:48: error: Name 'gid' already defined on line 40
volumes/fs/operations/group.py:48: error: "Callable[[Group], Any]" has no attribute "setter"

volumes/fs/operations/group.py: note: In function "open_group":
volumes/fs/operations/group.py:170: error: Property "uid" defined in "Group" is read-only
volumes/fs/operations/group.py:171: error: Property "gid" defined in "Group" is read-only

volumes/fs/operations/versions/subvolume_base.py: note: In class "SubvolumeBase":
volumes/fs/operations/versions/subvolume_base.py:45: error: Name 'uid' already defined on line 33
volumes/fs/operations/versions/subvolume_base.py:45: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:49: error: Name 'gid' already defined on line 37
volumes/fs/operations/versions/subvolume_base.py:49: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:53: error: Name 'mode' already defined on line 41
volumes/fs/operations/versions/subvolume_base.py:53: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"

Signed-off-by: Michael Fritch <[email protected]>
mgfritch added a commit to mgfritch/ceph that referenced this issue Mar 2, 2020
workaround for mypy issue:
python/mypy#1465

fixes mypy errors:

volumes/fs/operations/group.py: note: In class "Group":
volumes/fs/operations/group.py:44: error: Name 'uid' already defined on line 36
volumes/fs/operations/group.py:44: error: "Callable[[Group], Any]" has no attribute "setter"
volumes/fs/operations/group.py:48: error: Name 'gid' already defined on line 40
volumes/fs/operations/group.py:48: error: "Callable[[Group], Any]" has no attribute "setter"

volumes/fs/operations/group.py: note: In function "open_group":
volumes/fs/operations/group.py:170: error: Property "uid" defined in "Group" is read-only
volumes/fs/operations/group.py:171: error: Property "gid" defined in "Group" is read-only

volumes/fs/operations/versions/subvolume_base.py: note: In class "SubvolumeBase":
volumes/fs/operations/versions/subvolume_base.py:45: error: Name 'uid' already defined on line 33
volumes/fs/operations/versions/subvolume_base.py:45: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:49: error: Name 'gid' already defined on line 37
volumes/fs/operations/versions/subvolume_base.py:49: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:53: error: Name 'mode' already defined on line 41
volumes/fs/operations/versions/subvolume_base.py:53: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"

Signed-off-by: Michael Fritch <[email protected]>
mgfritch added a commit to mgfritch/ceph that referenced this issue Mar 2, 2020
workaround for mypy issue:
python/mypy#1465

fixes mypy errors:

volumes/fs/operations/group.py: note: In class "Group":
volumes/fs/operations/group.py:44: error: Name 'uid' already defined on line 36
volumes/fs/operations/group.py:44: error: "Callable[[Group], Any]" has no attribute "setter"
volumes/fs/operations/group.py:48: error: Name 'gid' already defined on line 40
volumes/fs/operations/group.py:48: error: "Callable[[Group], Any]" has no attribute "setter"

volumes/fs/operations/group.py: note: In function "open_group":
volumes/fs/operations/group.py:170: error: Property "uid" defined in "Group" is read-only
volumes/fs/operations/group.py:171: error: Property "gid" defined in "Group" is read-only

volumes/fs/operations/versions/subvolume_base.py: note: In class "SubvolumeBase":
volumes/fs/operations/versions/subvolume_base.py:45: error: Name 'uid' already defined on line 33
volumes/fs/operations/versions/subvolume_base.py:45: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:49: error: Name 'gid' already defined on line 37
volumes/fs/operations/versions/subvolume_base.py:49: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:53: error: Name 'mode' already defined on line 41
volumes/fs/operations/versions/subvolume_base.py:53: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"

Signed-off-by: Michael Fritch <[email protected]>
vshankar pushed a commit to ceph/ceph-ci that referenced this issue Mar 3, 2020
workaround for mypy issue:
python/mypy#1465

fixes mypy errors:

volumes/fs/operations/group.py: note: In class "Group":
volumes/fs/operations/group.py:44: error: Name 'uid' already defined on line 36
volumes/fs/operations/group.py:44: error: "Callable[[Group], Any]" has no attribute "setter"
volumes/fs/operations/group.py:48: error: Name 'gid' already defined on line 40
volumes/fs/operations/group.py:48: error: "Callable[[Group], Any]" has no attribute "setter"

volumes/fs/operations/group.py: note: In function "open_group":
volumes/fs/operations/group.py:170: error: Property "uid" defined in "Group" is read-only
volumes/fs/operations/group.py:171: error: Property "gid" defined in "Group" is read-only

volumes/fs/operations/versions/subvolume_base.py: note: In class "SubvolumeBase":
volumes/fs/operations/versions/subvolume_base.py:45: error: Name 'uid' already defined on line 33
volumes/fs/operations/versions/subvolume_base.py:45: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:49: error: Name 'gid' already defined on line 37
volumes/fs/operations/versions/subvolume_base.py:49: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:53: error: Name 'mode' already defined on line 41
volumes/fs/operations/versions/subvolume_base.py:53: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"

Signed-off-by: Michael Fritch <[email protected]>
mgfritch added a commit to mgfritch/ceph that referenced this issue Mar 3, 2020
workaround for mypy issue:
python/mypy#1465

fixes mypy errors:

volumes/fs/operations/group.py: note: In class "Group":
volumes/fs/operations/group.py:44: error: Name 'uid' already defined on line 36
volumes/fs/operations/group.py:44: error: "Callable[[Group], Any]" has no attribute "setter"
volumes/fs/operations/group.py:48: error: Name 'gid' already defined on line 40
volumes/fs/operations/group.py:48: error: "Callable[[Group], Any]" has no attribute "setter"

volumes/fs/operations/group.py: note: In function "open_group":
volumes/fs/operations/group.py:170: error: Property "uid" defined in "Group" is read-only
volumes/fs/operations/group.py:171: error: Property "gid" defined in "Group" is read-only

volumes/fs/operations/versions/subvolume_base.py: note: In class "SubvolumeBase":
volumes/fs/operations/versions/subvolume_base.py:45: error: Name 'uid' already defined on line 33
volumes/fs/operations/versions/subvolume_base.py:45: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:49: error: Name 'gid' already defined on line 37
volumes/fs/operations/versions/subvolume_base.py:49: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:53: error: Name 'mode' already defined on line 41
volumes/fs/operations/versions/subvolume_base.py:53: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"

Fixes: https://tracker.ceph.com/issues/44393
Signed-off-by: Michael Fritch <[email protected]>
mgfritch added a commit to mgfritch/ceph that referenced this issue Mar 5, 2020
workaround for mypy issue:
python/mypy#1465

fixes mypy errors:

volumes/fs/operations/group.py: note: In class "Group":
volumes/fs/operations/group.py:44: error: Name 'uid' already defined on line 36
volumes/fs/operations/group.py:44: error: "Callable[[Group], Any]" has no attribute "setter"
volumes/fs/operations/group.py:48: error: Name 'gid' already defined on line 40
volumes/fs/operations/group.py:48: error: "Callable[[Group], Any]" has no attribute "setter"

volumes/fs/operations/group.py: note: In function "open_group":
volumes/fs/operations/group.py:170: error: Property "uid" defined in "Group" is read-only
volumes/fs/operations/group.py:171: error: Property "gid" defined in "Group" is read-only

volumes/fs/operations/versions/subvolume_base.py: note: In class "SubvolumeBase":
volumes/fs/operations/versions/subvolume_base.py:45: error: Name 'uid' already defined on line 33
volumes/fs/operations/versions/subvolume_base.py:45: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:49: error: Name 'gid' already defined on line 37
volumes/fs/operations/versions/subvolume_base.py:49: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"
volumes/fs/operations/versions/subvolume_base.py:53: error: Name 'mode' already defined on line 41
volumes/fs/operations/versions/subvolume_base.py:53: error: "Callable[[SubvolumeBase], Any]" has no attribute "setter"

Fixes: https://tracker.ceph.com/issues/44393
Signed-off-by: Michael Fritch <[email protected]>
@John15321
Copy link

This problem seems to be persistent and still confuses people a lot maybe it's time to fix it?

@AlexWaygood AlexWaygood added the topic-descriptors Properties, class vs. instance attributes label Mar 24, 2022
Volham22 added a commit to Scille/parsec-cloud that referenced this issue Nov 2, 2022
* This is a mypy issue: python/mypy#1465
    Mypy reports false positive when a decorated setter isn't declare
    right above its getter.
Volham22 added a commit to Scille/parsec-cloud that referenced this issue Nov 2, 2022
* This is a mypy issue: python/mypy#1465
    Mypy reports false positive when a decorated setter isn't declare
    right above its getter.
@samskiter
Copy link

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.

@asarkar
Copy link

asarkar commented Sep 23, 2023

"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.

a-detiste added a commit to a-detiste/duecredit that referenced this issue Nov 12, 2023
a-detiste added a commit to a-detiste/duecredit that referenced this issue Nov 12, 2023
bouweandela added a commit to bouweandela/iris that referenced this issue Jun 26, 2024
trexfeathers added a commit to SciTools/iris that referenced this issue Jun 26, 2024
* Enable type hint checking

* Add whatsnew entry

* Add class variable annotation

* Update line numbers in doctests

* Implement suggestions from code review

* Update docs/src/whatsnew/latest.rst

Co-authored-by: Martin Yeo <[email protected]>

* Workaround for python/mypy#1465

Co-authored-by: Martin Yeo <[email protected]>

* Also apply workaround for bounds

* Add type hint

---------

Co-authored-by: Martin Yeo <[email protected]>
nelimee added a commit to nelimee/tqec that referenced this issue Jul 28, 2024
See python/mypy#1465 for information
on the changes in schedule.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-descriptors Properties, class vs. instance attributes
Projects
None yet
Development

No branches or pull requests