Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions mypy/exprtotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mypy.nodes import (
Expression, NameExpr, MemberExpr, IndexExpr, TupleExpr,
ListExpr, StrExpr, BytesExpr, EllipsisExpr
ListExpr, StrExpr, BytesExpr, UnicodeExpr, EllipsisExpr
)
from mypy.parsetype import parse_str_as_type, TypeParseError
from mypy.types import Type, UnboundType, TypeList, EllipsisType
Expand Down Expand Up @@ -43,7 +43,7 @@ def expr_to_unanalyzed_type(expr: Expression) -> Type:
elif isinstance(expr, ListExpr):
return TypeList([expr_to_unanalyzed_type(t) for t in expr.items],
line=expr.line, column=expr.column)
elif isinstance(expr, (StrExpr, BytesExpr)):
elif isinstance(expr, (StrExpr, BytesExpr, UnicodeExpr)):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you search to see if there are other places that might have a similar bug?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick grep it looks like there might be -- I'll take a closer look tomorrow!

# Parse string literal type.
try:
result = parse_str_as_type(expr.value, expr.line)
Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/check-python2.test
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,9 @@ def foo() -> int:
# flags: --fast-parser
import __builtin__
__builtin__.str

[case testUnicodeAlias]
from typing import List
Alias = List[u'Foo']
class Foo: pass
[builtins_py2 fixtures/python2.pyi]
5 changes: 5 additions & 0 deletions test-data/unit/fixtures/python2.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Generic, Iterable, TypeVar

class object:
def __init__(self) -> None: pass

Expand All @@ -10,4 +12,7 @@ class int: pass
class str: pass
class unicode: pass

T = TypeVar('T')
class list(Iterable[T], Generic[T]): pass

# Definition of None is implicit