File tree 3 files changed +31
-1
lines changed
astroid/nodes/scoped_nodes 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ What's New in astroid 3.3.3?
13
13
============================
14
14
Release date: TBA
15
15
16
+ * Fix inference regression with property setters
17
+
18
+ Closes pylint-dev/pylint#9811
16
19
17
20
18
21
What's New in astroid 3.3.2?
Original file line number Diff line number Diff line change @@ -2487,6 +2487,16 @@ def igetattr(
2487
2487
if attr .parent and attr .parent .scope () == first_scope
2488
2488
]
2489
2489
functions = [attr for attr in attributes if isinstance (attr , FunctionDef )]
2490
+ setter = None
2491
+ for function in functions :
2492
+ dec_names = function .decoratornames (context = context )
2493
+ for dec_name in dec_names :
2494
+ if dec_name is util .Uninferable :
2495
+ continue
2496
+ if dec_name .split ("." )[- 1 ] == "setter" :
2497
+ setter = function
2498
+ if setter :
2499
+ break
2490
2500
if functions :
2491
2501
# Prefer only the last function, unless a property is involved.
2492
2502
last_function = functions [- 1 ]
@@ -2510,7 +2520,7 @@ def igetattr(
2510
2520
elif isinstance (inferred , objects .Property ):
2511
2521
function = inferred .function
2512
2522
if not class_context :
2513
- if not context .callcontext :
2523
+ if not context .callcontext and not setter :
2514
2524
context .callcontext = CallContext (
2515
2525
args = function .args .arguments , callee = function
2516
2526
)
Original file line number Diff line number Diff line change @@ -4416,6 +4416,23 @@ def func():
4416
4416
inferred = list (node .inferred ())
4417
4417
assert [const .value for const in inferred ] == [42 , False ]
4418
4418
4419
+ def test_infer_property_setter (self ) -> None :
4420
+ node = extract_node (
4421
+ """
4422
+ class PropertyWithSetter:
4423
+ @property
4424
+ def host(self):
4425
+ return self._host
4426
+
4427
+ @host.setter
4428
+ def host(self, value: str):
4429
+ self._host = value
4430
+
4431
+ PropertyWithSetter().host #@
4432
+ """
4433
+ )
4434
+ assert not isinstance (next (node .infer ()), Instance )
4435
+
4419
4436
def test_delayed_attributes_without_slots (self ) -> None :
4420
4437
ast_node = extract_node (
4421
4438
"""
You can’t perform that action at this time.
0 commit comments