Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,14 @@ def parse_type_string(
string expression "blah" using this function.
"""
try:
_, node = parse_type_comment(expr_string.strip(), line=line, column=column, errors=None)
try:
_, node = parse_type_comment(
expr_string.strip(), line=line, column=column, errors=None
)
except SyntaxError:
_, node = parse_type_comment(
f"({expr_string.strip()})", line=line, column=column, errors=None
)
if isinstance(node, UnboundType) and node.original_str_expr is None:
node.original_str_expr = expr_string
node.original_str_fallback = expr_fallback_name
Expand Down
16 changes: 16 additions & 0 deletions test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,19 @@ s2: str = 42 # E: Incompatible types in assignment (expression has type "int",
s3: str = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "str")
[file c.py]
s3: str = 'foo'

[case testMultilineQuotedAnnotation]
x: """

int |
str

"""
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"

y: """(
int |
str
)
"""
reveal_type(y) # N: Revealed type is "Union[builtins.int, builtins.str]"