Skip to content

Commit

Permalink
fix empty body bug, extra caution for async strip
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Jun 21, 2023
1 parent 4ff12c3 commit 73a77b3
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,17 +538,20 @@ def translate_stmt_list(

# Slow case for stripping function bodies
if can_strip and self.strip_function_bodies:
if stack[-2:] == ["C", "F"] and not is_possible_trivial_body(res):
# We only strip method bodies if they don't assign to an attribute, as
# this may define an attribute which has an externally visible effect.
visitor = FindAttributeAssign()
for s in res:
s.accept(visitor)
if visitor.found:
can_strip = False
break

if can_strip and is_coroutine:
if stack[-2:] == ["C", "F"]:
if is_possible_trivial_body(res):
can_strip = False
else:
# We only strip method bodies if they don't assign to an attribute, as
# this may define an attribute which has an externally visible effect.
visitor = FindAttributeAssign()
for s in res:
s.accept(visitor)
if visitor.found:
can_strip = False
break

if can_strip and stack[-1] == "F" and is_coroutine:
# Yields inside an async function affect the return type and should not
# be stripped.
yield_visitor = FindYield()
Expand Down

0 comments on commit 73a77b3

Please sign in to comment.