@@ -54,22 +54,27 @@ def _looks_like_parents_name(node: nodes.Name) -> bool:
5454 frame , stmts = node .lookup (node .name )
5555 if not stmts :
5656 return False
57-
57+
5858 # Check each assignment statement
5959 for stmt in stmts :
6060 if isinstance (stmt , nodes .AssignName ):
6161 # Get the parent Assign node
6262 assign_node = stmt .parent
6363 if isinstance (assign_node , nodes .Assign ):
6464 # Check if the value is an Attribute access to .parents
65- if (isinstance (assign_node .value , nodes .Attribute )
66- and assign_node .value .attrname == "parents" ):
65+ if (
66+ isinstance (assign_node .value , nodes .Attribute )
67+ and assign_node .value .attrname == "parents"
68+ ):
6769 try :
6870 # Check if the attribute is from a Path object
6971 value = next (assign_node .value .expr .infer ())
70- if (isinstance (value , bases .Instance )
72+ if (
73+ isinstance (value , bases .Instance )
7174 and isinstance (value ._proxied , nodes .ClassDef )
72- and value .qname () in ("pathlib.Path" , "pathlib._local.Path" )):
75+ and value .qname ()
76+ in ("pathlib.Path" , "pathlib._local.Path" )
77+ ):
7378 return True
7479 except (InferenceError , StopIteration ):
7580 pass
@@ -85,21 +90,26 @@ def infer_parents_name(
8590 if PY313 :
8691 # For Python 3.13+, parents is a tuple
8792 from astroid import nodes
93+
8894 # Create a tuple that behaves like Path.parents
8995 parents_tuple = nodes .Tuple ()
9096 # Add some mock Path elements to make indexing work
9197 path_cls = next (_extract_single_node (PATH_TEMPLATE ).infer ())
92- parents_tuple .elts = [path_cls .instantiate_class () for _ in range (3 )] # Mock some parents
98+ parents_tuple .elts = [
99+ path_cls .instantiate_class () for _ in range (3 )
100+ ] # Mock some parents
93101 return iter ([parents_tuple ])
94102 else :
95103 # For older versions, it's a _PathParents object
96104 # We need to create a mock _PathParents instance that behaves correctly
97- parents_cls = _extract_single_node ("""
105+ parents_cls = _extract_single_node (
106+ """
98107class _PathParents:
99108 def __getitem__(self, key):
100109 from pathlib import Path
101110 return Path()
102- """ )
111+ """
112+ )
103113 return iter ([parents_cls .instantiate_class ()])
104114
105115
0 commit comments