Skip to content

Commit

Permalink
mypyc: fix runtime type violation
Browse files Browse the repository at this point in the history
`normalized` is typed as str which is a problem as the fallback assigns
`value` to `normalized` which can be anything. This wasn't caught
statically because `value` is typed as Any which effectively disables
type checking.
  • Loading branch information
ichard26 committed Jan 14, 2022
1 parent f697d83 commit cdea55b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/black/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def stringify_ast(node: Union[ast.AST, ast3.AST], depth: int = 0) -> Iterator[st
break

try:
value = getattr(node, field)
value: object = getattr(node, field)
except AttributeError:
continue

Expand Down Expand Up @@ -237,6 +237,7 @@ def stringify_ast(node: Union[ast.AST, ast3.AST], depth: int = 0) -> Iterator[st
yield from stringify_ast(value, depth + 2)

else:
normalized: object
# Constant strings may be indented across newlines, if they are
# docstrings; fold spaces after newlines when comparing. Similarly,
# trailing and leading space may be removed.
Expand Down

0 comments on commit cdea55b

Please sign in to comment.