Skip to content

Commit

Permalink
Removed isinstance in favor of libcst.ensure_type
Browse files Browse the repository at this point in the history
  • Loading branch information
surge119 committed Jun 5, 2024
1 parent 1ecee30 commit fa788ad
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/fixit/rules/deprecated_abc_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,14 @@ def visit_ImportAlias(self, node: cst.ImportAlias) -> None:
"""
This catches the `import collections.<ABC>` cases.
"""
if (
m.matches(
node,
m.ImportAlias(
name=m.Attribute(
value=m.Name("collections"),
attr=m.OneOf(*[m.Name(abc) for abc in ABCS]),
)
),
)
# This is necessary for the typecheck. Otherwise when replacing the node
# and using `attr=node.name.attr`, the type checker will complain since
# node.name is `Union[cst.Name | cst.Attribute]`
and isinstance(node.name, cst.Attribute)
if m.matches(
node,
m.ImportAlias(
name=m.Attribute(
value=m.Name("collections"),
attr=m.OneOf(*[m.Name(abc) for abc in ABCS]),
)
),
):
self.report(
node,
Expand All @@ -261,7 +255,7 @@ def visit_ImportAlias(self, node: cst.ImportAlias) -> None:
value=cst.Name(value="collections"),
attr=cst.Name(value="abc"),
),
attr=node.name.attr,
attr=cst.ensure_type(node.name, cst.Attribute).attr,
)
),
)
Expand Down

0 comments on commit fa788ad

Please sign in to comment.