Skip to content

Commit

Permalink
Accept multiline quoted annotations (#16765)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja authored Jan 12, 2024
1 parent 35f402c commit edebe02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def parse_type_string(
string expression "blah" using this function.
"""
try:
_, node = parse_type_comment(expr_string.strip(), line=line, column=column, errors=None)
_, node = parse_type_comment(f"({expr_string})", 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]"

0 comments on commit edebe02

Please sign in to comment.