Skip to content

Commit

Permalink
fix crash when subscripts are in attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed May 27, 2024
1 parent aedd6e4 commit 847f90c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions flake8_async/visitors/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,15 @@ def build_cst_matcher(attr: str) -> m.BaseExpression:
return m.Attribute(value=build_cst_matcher(body), attr=m.Name(value=tail))


def identifier_to_string(attr: cst.Name | cst.Attribute) -> str:
def identifier_to_string(attr: cst.Name | cst.Attribute) -> str | None:
if isinstance(attr, cst.Name):
return attr.value
assert isinstance(attr.value, (cst.Attribute, cst.Name))
return identifier_to_string(attr.value) + "." + attr.attr.value
if not isinstance(attr.value, (cst.Attribute, cst.Name)):
return None
lhs = identifier_to_string(attr.value)
if lhs is None:
return None
return lhs + "." + attr.attr.value


def with_has_call(
Expand Down Expand Up @@ -383,10 +387,10 @@ def with_has_call(
assert isinstance(item.item, cst.Call)
assert isinstance(res["base"], (cst.Name, cst.Attribute))
assert isinstance(res["function"], cst.Name)
base_string = identifier_to_string(res["base"])
assert base_string is not None, "subscripts should never get matched"
res_list.append(
AttributeCall(
item.item, identifier_to_string(res["base"]), res["function"].value
)
AttributeCall(item.item, base_string, res["function"].value)
)
return res_list

Expand Down
4 changes: 4 additions & 0 deletions tests/eval_files/async120.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ async def foo():
# or any lambda thing
my_lambda = lambda: asyncio.create_task(*args)
my_lambda(*args)

# don't crash

args.nodes[args].append(args)

0 comments on commit 847f90c

Please sign in to comment.