Skip to content

Commit 213b2a6

Browse files
Avoid inferring all subscripted names in pathlib brain (#1671)
1 parent 1c3c18f commit 213b2a6

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

astroid/brain/brain_pathlib.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
def _looks_like_parents_subscript(node: nodes.Subscript) -> bool:
2121
if not (
22-
isinstance(node.value, nodes.Name)
23-
or isinstance(node.value, nodes.Attribute)
24-
and node.value.attrname == "parents"
22+
isinstance(node.value, nodes.Attribute) and node.value.attrname == "parents"
2523
):
2624
return False
2725

tests/unittest_brain_pathlib.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,14 @@ def test_inference_parents() -> None:
2828

2929
def test_inference_parents_subscript_index() -> None:
3030
"""Test inference of ``pathlib.Path.parents``, accessed by index."""
31-
parents, path = astroid.extract_node(
31+
path = astroid.extract_node(
3232
"""
3333
from pathlib import Path
3434
3535
current_path = Path().resolve()
36-
path_parents = current_path.parents
37-
path_parents #@
38-
path_parents[2] #@
36+
current_path.parents[2] #@
3937
"""
4038
)
41-
inferred = parents.inferred()
42-
assert len(inferred) == 1
43-
assert isinstance(inferred[0], bases.Instance)
44-
assert inferred[0].qname() == "pathlib._PathParents"
4539

4640
inferred = path.inferred()
4741
assert len(inferred) == 1

0 commit comments

Comments
 (0)