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/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ def is_at_ellipsis(self) -> bool:

# Regexps used by lex_number

# Decimal/hex/octal literal or integer complex literal
number_exp1 = re.compile('0[xXoO][0-9a-fA-F]+|[0-9]+')
# Decimal/hex/octal/binary literal or integer complex literal
number_exp1 = re.compile('0[xXoObB][0-9a-fA-F]+|[0-9]+')
# Float literal, e.g. '1.23' or '12e+34' or '1.2j'
number_exp2 = re.compile(
r'[0-9]*\.[0-9]*([eE][-+]?[0-9]+)?|[0-9]+[eE][-+]?[0-9]+')
Expand Down
10 changes: 1 addition & 9 deletions mypy/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,15 +1268,7 @@ def parse_name_expr(self) -> NameExpr:

def parse_int_expr(self) -> IntExpr:
tok = self.expect_type(IntLit)
s = tok.string
v = 0
if len(s) > 2 and s[1] in 'xX':
v = int(s[2:], 16)
elif len(s) > 2 and s[1] in 'oO':
v = int(s[2:], 8)
else:
v = int(s)
node = IntExpr(v)
node = IntExpr(int(tok.string, 0))
return node

def parse_str_expr(self) -> Node:
Expand Down
8 changes: 5 additions & 3 deletions mypy/test/data/parse.test
Original file line number Diff line number Diff line change
Expand Up @@ -1665,16 +1665,18 @@ MypyFile:1(
Block:1(
PassStmt:2())))

[case testHexAndOctLiterals]
0xa, 0Xaf, 0o7, 0O12
[case testHexOctBinLiterals]
0xa, 0Xaf, 0o7, 0O12, 0b1, 0B101
[out]
MypyFile:1(
ExpressionStmt:1(
TupleExpr:1(
IntExpr(10)
IntExpr(175)
IntExpr(7)
IntExpr(10))))
IntExpr(10)
IntExpr(1)
IntExpr(5))))

[case testImportFromWithParens]
from x import (y)
Expand Down
4 changes: 4 additions & 0 deletions mypy/test/testlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def test_oct_int_literals(self):
self.assert_lex('0o0 0o127 0O1',
'IntLit(0o0) IntLit( 0o127) IntLit( 0O1) ...')

def test_bin_int_literals(self):
self.assert_lex('0b0 0b110 0B1',
'IntLit(0b0) IntLit( 0b110) IntLit( 0B1) ...')

def test_float_literals(self):
self.assert_lex('1.2 .1 1.',
'FloatLit(1.2) FloatLit( .1) FloatLit( 1.) ...')
Expand Down