10000 Update the fast parser to work with Python 2.7 by ddfisher · Pull Request #1418 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Update the fast parser to work with Python 2.7 #1418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2016
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
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def visit_op_expr(self, e: OpExpr) -> Type:
if e.op == '*' and isinstance(e.left, ListExpr):
# Expressions of form [...] * e get special type inference.
return self.check_list_multiply(e)
if e.op == '%' and isinstance(e.left, StrExpr):
if e.op == '%' and isinstance(e.left, (StrExpr, BytesExpr)):
return self.strfrm_checker.check_str_interpolation(cast(StrExpr, e.left), e.right)
left_type = self.accept(e.left)

Expand Down
6 changes: 3 additions & 3 deletions mypy/checkstrformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Type, AnyType, TupleType, Instance, UnionType
)
from mypy.nodes import (
Node, StrExpr, TupleExpr, DictExpr, Context
Node, StrExpr, BytesExpr, TupleExpr, DictExpr, Context
)
if False:
# break import cycle only needed for mypy
Expand Down Expand Up @@ -136,7 +136,7 @@ def check_simple_str_interpolation(self, specifiers: List[ConversionSpecifier],
def check_mapping_str_interpolation(self, specifiers: List[ConversionSpecifier],
replacements: Node) -> None:
dict_with_only_str_literal_keys = (isinstance(replacements, DictExpr) and
all(isinstance(k, StrExpr)
all(isinstance(k, (StrExpr, BytesExpr))
for k, v in cast(DictExpr, replacements).items))
if dict_with_only_str_literal_keys:
mapping = {} # type: Dict[str, Type]
Expand Down Expand Up @@ -255,7 +255,7 @@ def check_type(type: Type = None) -> None:
def check_node(node: Node) -> None:
"""int, or str with length 1"""
type = self.accept(node, expected_type)
if isinstance(node, StrExpr) and len(cast(StrExpr, node).value) != 1:
if isinstance(node, (StrExpr, BytesExpr)) and len(cast(StrExpr, node).value) != 1:
self.msg.requires_int_or_char(context)
check_type(type)

Expand Down
4 changes: 2 additions & 2 deletions mypy/exprtotype.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Translate an expression (Node) to a Type value."""

from mypy.nodes import (
Node, NameExpr, MemberExpr, IndexExpr, TupleExpr, ListExpr, StrExpr, EllipsisExpr
Node, NameExpr, MemberExpr, IndexExpr, TupleExpr, ListExpr, StrExpr, BytesExpr, EllipsisExpr
)
from mypy.parsetype import parse_str_as_type, TypeParseError
from mypy.types import Type, UnboundType, TypeList, EllipsisType
Expand Down Expand Up @@ -42,7 +42,7 @@ def expr_to_unanalyzed_type(expr: Node) -> Type:
elif isinstance(expr, ListExpr):
return TypeList([expr_to_unanalyzed_type(t) for t in expr.items],
line=expr.line)
elif isinstance(expr, StrExpr):
elif isinstance(expr, (StrExpr, BytesExpr)):
# Parse string literal type.
try:
result = parse_str_as_type(expr.value, expr.line)
Expand Down
4284
Loading
0