8000 Update the fast parser to work with Python 2.7 (#1418) · python/mypy@930b07e · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 930b07e

Browse files
ddfishergvanrossum
authored andcommitted
Update the fast parser to work with Python 2.7 (#1418)
1 parent 432f706 commit 930b07e

File tree

6 files changed

+212
-181
lines changed

6 files changed

+212
-181
lines changed

mypy/checkexpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ def visit_op_expr(self, e: OpExpr) -> Type:
861861
if e.op == '*' and isinstance(e.left, ListExpr):
862862
# Expressions of form [...] * e get special type inference.
863863
return self.check_list_multiply(e)
864-
if e.op == '%' and isinstance(e.left, StrExpr):
864+
if e.op == '%' and isinstance(e.left, (StrExpr, BytesExpr)):
865865
return self.strfrm_checker.check_str_interpolation(cast(StrExpr, e.left), e.right)
866866
left_type = self.accept(e.left)
867867

mypy/checkstrformat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Type, AnyType, TupleType, Instance, UnionType
99
)
1010
from mypy.nodes import (
11-
Node, StrExpr, TupleExpr, DictExpr, Context
11+
Node, StrExpr, BytesExpr, TupleExpr, DictExpr, Context
1212
)
1313
if False:
1414
# break import cycle only needed for mypy
@@ -136,7 +136,7 @@ def check_simple_str_interpolation(self, specifiers: List[ConversionSpecifier],
136136
def check_mapping_str_interpolation(self, specifiers: List[ConversionSpecifier],
137137
replacements: Node) -> None:
138138
dict_with_only_str_literal_keys = (isinstance(replacements, DictExpr) and
139-
all(isinstance(k, StrExpr)
139+
all(isinstance(k, (StrExpr, BytesExpr))
140140
for k, v in cast(DictExpr, replacements).items))
141141
if dict_with_only_str_literal_keys:
142142
mapping = {} # type: Dict[str, Type]
@@ -255,7 +255,7 @@ def check_type(type: Type = None) -> None:
255255
def check_node(node: Node) -> None:
256256
"""int, or str with length 1"""
257257
type = self.accept(node, expected_type)
258-
if isinstance(node, StrExpr) and len(cast(StrExpr, node).value) != 1:
258+
if isinstance(node, (StrExpr, BytesExpr)) and len(cast(StrExpr, node).value) != 1:
259259
self.msg.requires_int_or_char(context)
260260
check_type(type)
261261

mypy/exprtotype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Translate an expression (Node) to a Type value."""
22

33
from mypy.nodes import (
4-
Node, NameExpr, MemberExpr, IndexExpr, TupleExpr, ListExpr, StrExpr, EllipsisExpr
4+
Node, NameExpr, MemberExpr, IndexExpr, TupleExpr, ListExpr, StrExpr, BytesExpr, EllipsisExpr
55
)
66
from mypy.parsetype import parse_str_as_type, TypeParseError
77
from mypy.types import Type, UnboundType, TypeList, EllipsisType
@@ -42,7 +42,7 @@ def expr_to_unanalyzed_type(expr: Node) -> Type:
4242
elif isinstance(expr, ListExpr):
4343
return TypeList([expr_to_unanalyzed_type(t) for t in expr.items],
4444
line=expr.line)
45-
elif isinstance(expr, StrExpr):
45+
elif isinstance(expr, (StrExpr, BytesExpr)):
4646
# Parse string literal type.
4747
try:
4848
result = parse_str_as_type(expr.value, expr.line)

0 commit comments

Comments
 (0)
0