File tree 3 files changed +32
-2
lines changed
astroid/nodes/scoped_nodes 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -13,12 +13,15 @@ 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
19
+
16
20
* Add annotation-only instance attributes to attrs classes to fix `no-member` false positives.
17
21
18
22
Closes #2514
19
23
20
24
21
-
22
25
What's New in astroid 3.3.2?
23
26
============================
24
27
Release date: 2024-08-11
Original file line number Diff line number Diff line change @@ -2506,6 +2506,16 @@ def igetattr(
2506
2506
if attr .parent and attr .parent .scope () == first_scope
2507
2507
]
2508
2508
functions = [attr for attr in attributes if isinstance (attr , FunctionDef )]
2509
+ setter = None
2510
+ for function in functions :
2511
+ dec_names = function .decoratornames (context = context )
2512
+ for dec_name in dec_names :
2513
+ if dec_name is util .Uninferable :
2514
+ continue
2515
+ if dec_name .split ("." )[- 1 ] == "setter" :
2516
+ setter = function
2517
+ if setter :
2518
+ break
2509
2519
if functions :
2510
2520
# Prefer only the last function, unless a property is involved.
2511
2521
last_function = functions [- 1 ]
@@ -2529,7 +2539,7 @@ def igetattr(
2529
2539
elif isinstance (inferred , objects .Property ):
2530
2540
function = inferred .function
2531
2541
if not class_context :
2532
- if not context .callcontext :
2542
+ if not context .callcontext and not setter :
2533
2543
context .callcontext = CallContext (
2534
2544
args = function .args .arguments , callee = function
2535
2545
)
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