-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
False positive for no-member with property setters #9811
Labels
Astroid
Related to astroid
Needs astroid update
Needs an astroid update (probably a release too) before being mergable
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
properties
Regression
Milestone
Comments
Sorry for the complexity of the example. It did not appear unless I added in the inheritance model and a multi-level nested reference matching what is used in the project I was working on when I discovered it. |
12 tasks
Thanks for the report. Regression in pylint-dev/astroid@0f9dfa6. |
I'm doubtful this is the best thing we can do, but a quick-n-dirty might be some variation of: diff --git a/astroid/nodes/scoped_nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes/scoped_nodes.py
index efd5439b..dbe5872e 100644
--- a/astroid/nodes/scoped_nodes/scoped_nodes.py
+++ b/astroid/nodes/scoped_nodes/scoped_nodes.py
@@ -2495,6 +2495,16 @@ class ClassDef( # pylint: disable=too-many-instance-attributes
if attr.parent and attr.parent.scope() == first_scope
]
functions = [attr for attr in attributes if isinstance(attr, FunctionDef)]
+ setter = None
+ for function in functions:
+ dec_names = function.decoratornames(context=context)
+ for dec_name in dec_names:
+ if dec_name is util.Uninferable:
+ continue
+ if dec_name.split(".")[-1] == "setter":
+ setter = function
+ if setter:
+ break
if functions:
# Prefer only the last function, unless a property is involved.
last_function = functions[-1]
@@ -2518,7 +2528,7 @@ class ClassDef( # pylint: disable=too-many-instance-attributes
elif isinstance(inferred, objects.Property):
function = inferred.function
if not class_context:
- if not context.callcontext:
+ if not context.callcontext and not setter:
context.callcontext = CallContext(
args=function.args.arguments, callee=function
) |
Slimmer reproducer: # pylint: disable=missing-module-docstring,missing-class-docstring, missing-function-docstring
class BugReport:
@property
def host(self):
return self._host
@host.setter
def host(self, value: str):
self._host = value
@property
def timezone(self):
return self.host.lower() # self.host should not infer as self ************* Module a
Desktop/a.py:14:15: E1101: Instance of 'BugReport' has no 'lower' member (no-member) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Astroid
Related to astroid
Needs astroid update
Needs an astroid update (probably a release too) before being mergable
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
properties
Regression
Bug description
Configuration
No response
Command used
Pylint output
Expected behavior
This should not show an error, all members referenced are defined. Notably it does not show an error in 3.12.3, appears to be a regression with 3.12.4
Pylint version
OS / Environment
MacOS 14.4.1
We also are seeing it in ubuntu containers running in github actions, like this run: https://github.com/home-assistant/supervisor/actions/runs/9904839873/job/27515699355 (same issue, appeared on upgrade to 3.12.4).
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: