Skip to content

Commit 7e2b3b4

Browse files
buckbaskinGuido van Rossum
authored and
Guido van Rossum
committed
Use pyversion variable to change bytes checking for python 3 less than 3.5 (#2191)
1 parent 62ad163 commit 7e2b3b4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

mypy/checkexpr.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,8 +966,15 @@ def visit_op_expr(self, e: OpExpr) -> Type:
966966
# Expressions of form [...] * e get special type inference.
967967
return self.check_list_multiply(e)
968968
if e.op == '%':
969-
if isinstance(e.left, (StrExpr, BytesExpr, UnicodeExpr)):
970-
return self.strfrm_checker.check_str_interpolation(e.left, e.right)
969+
pyversion = self.chk.options.python_version
970+
if pyversion[0] == 3:
971+
if isinstance(e.left, BytesExpr) and pyversion[1] >= 5:
972+
return self.strfrm_checker.check_str_interpolation(e.left, e.right)
973+
if isinstance(e.left, StrExpr):
974+
return self.strfrm_checker.check_str_interpolation(e.left, e.right)
975+
elif pyversion[0] <= 2:
976+
if isinstance(e.left, (StrExpr, BytesExpr, UnicodeExpr)):
977+
return self.strfrm_checker.check_str_interpolation(e.left, e.right)
971978
left_type = self.accept(e.left)
972979

973980
if e.op in nodes.op_methods:

mypy/checkstrformat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def __init__(self,
5757

5858
# TODO: In Python 3, the bytes formatting has a more restricted set of options
5959
# compared to string formatting.
60-
# TODO: Bytes formatting in Python 3 is only supported in 3.5 and up.
6160
def check_str_interpolation(self,
6261
str: Union[StrExpr, BytesExpr, UnicodeExpr],
6362
replacements: Node) -> Type:

0 commit comments

Comments
 (0)