File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,23 @@ def parse_functiondef(self, node):
267
267
if node .name == "__init__" :
268
268
for child in node .get_children ():
269
269
if isinstance (child , (astroid .nodes .Assign , astroid .nodes .AnnAssign )):
270
+ # Verify we are assigning to self.
271
+ if isinstance (child , astroid .nodes .Assign ):
272
+ targets = child .targets
273
+ else :
274
+ targets = [child .target ]
275
+
276
+ target_ok = True
277
+ for target in targets :
278
+ if not isinstance (target , astroid .nodes .AssignAttr ):
279
+ target_ok = False
280
+ break
281
+ _object = target .expr
282
+ if not isinstance (_object , astroid .nodes .Name ) or _object .name != "self" :
283
+ target_ok = False
284
+ break
285
+ if not target_ok :
286
+ continue
270
287
child_data = self ._parse_assign (child )
271
288
result .extend (data for data in child_data )
272
289
Original file line number Diff line number Diff line change @@ -92,6 +92,12 @@ def __init__(self):
92
92
self .instance_var : bool = True
93
93
"""This is an instance_var."""
94
94
95
+ self .subobject : object = object ()
96
+ self .subobject .subobject_variable = 1
97
+
98
+ local_variable_typed : int = 0
99
+ local_variable_untyped = 2
100
+
95
101
async def async_method (self , wait : bool ) -> int :
96
102
if wait :
97
103
await asyncio .sleep (1 )
Original file line number Diff line number Diff line change @@ -459,6 +459,13 @@ def test_annotations(self, parse):
459
459
460
460
assert example_file .find (id = "example.A.instance_var" )
461
461
462
+ # Locals are excluded
463
+ assert not example_file .find (id = "example.A.local_variable_typed" )
464
+ assert not example_file .find (id = "example.A.local_variable_untyped" )
465
+
466
+ # Assignments to subobjects are excluded
467
+ assert not example_file .find (id = "example.A.subobject_variable" )
468
+
462
469
global_a = example_file .find (id = "example.global_a" )
463
470
assert global_a
464
471
global_a_value = global_a .find_all (class_ = "property" )
You can’t perform that action at this time.
0 commit comments