-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Comments
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
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
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
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
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
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
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
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
#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 |
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 <mfritch@suse.com>
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 <mfritch@suse.com>
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 <mfritch@suse.com>
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 <mfritch@suse.com>
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 <mfritch@suse.com>
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 <mfritch@suse.com>
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 <mfritch@suse.com>
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 <mfritch@suse.com>
Move setters next to getters because mypy throws a false-positive if the methods are not adjacent (see python/mypy#1465).
* Add basic mypy configuration file * Move setters next to getters (see python/mypy#1465) * Fix open modes namedtuple name consistency * Fix fake file size mypy errors * Ignore missing attributes of pathlib, ignore invalid type for parent * Fix pure path parent type * Ignore module spec type error * Add some patcher class attribute annotations * Add setup.py annotations
…e MANIFEST.in README.md docs extra_requirements.txt mypy.ini pyfakefs requirements.txt setup.cfg setup.py tox.ini Add basic mypy configuration file CHANGES.md CONTRIBUTING.md COPYING Dockerfile MANIFEST.in README.md docs extra_requirements.txt mypy.ini pyfakefs requirements.txt setup.cfg setup.py tox.ini Move setters next to getters (see python/mypy#1465) CHANGES.md CONTRIBUTING.md COPYING Dockerfile MANIFEST.in README.md docs extra_requirements.txt mypy.ini pyfakefs requirements.txt setup.cfg setup.py tox.ini Fix open modes namedtuple name consistency CHANGES.md CONTRIBUTING.md COPYING Dockerfile MANIFEST.in README.md docs extra_requirements.txt mypy.ini pyfakefs requirements.txt setup.cfg setup.py tox.ini Fix fake file size mypy errors CHANGES.md CONTRIBUTING.md COPYING Dockerfile MANIFEST.in README.md docs extra_requirements.txt mypy.ini pyfakefs requirements.txt setup.cfg setup.py tox.ini Ignore missing attributes of pathlib, ignore invalid type for parent CHANGES.md CONTRIBUTING.md COPYING Dockerfile MANIFEST.in README.md docs extra_requirements.txt mypy.ini pyfakefs requirements.txt setup.cfg setup.py tox.ini Fix pure path parent type CHANGES.md CONTRIBUTING.md COPYING Dockerfile MANIFEST.in README.md docs extra_requirements.txt mypy.ini pyfakefs requirements.txt setup.cfg setup.py tox.ini Ignore module spec type error CHANGES.md CONTRIBUTING.md COPYING Dockerfile MANIFEST.in README.md docs extra_requirements.txt mypy.ini pyfakefs requirements.txt setup.cfg setup.py tox.ini Add some patcher class attribute annotations CHANGES.md CONTRIBUTING.md COPYING Dockerfile MANIFEST.in README.md docs extra_requirements.txt mypy.ini pyfakefs requirements.txt setup.cfg setup.py tox.ini Add setup.py annotations
This problem seems to be persistent and still confuses people a lot maybe it's time to fix it? |
* This is a mypy issue: python/mypy#1465 Mypy reports false positive when a decorated setter isn't declare right above its getter.
* This is a mypy issue: python/mypy#1465 Mypy reports false positive when a decorated setter isn't declare right above its getter.
Thanks for posting this - also struggling with this. Is there any known workaround? Specifically I wanted to override a property setter. |
"No attribute" along with "Untyped decorator" error.
Running mypy with
Line 28 happens to be the |
+ workaround a mypy bug: python/mypy#1465
+ workaround a mypy bug: python/mypy#1465
Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>
* 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 <40734014+trexfeathers@users.noreply.github.com> * Workaround for python/mypy#1465 Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> * Also apply workaround for bounds * Add type hint --------- Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>
The following code incorrectly raises an error:
Error:
Commenting out the
_other
method will fix the error.The text was updated successfully, but these errors were encountered: