Skip to content

Commit 4a9e32e

Browse files
committed
Fix parsing of octal literal by patchedast
1 parent 4293428 commit 4a9e32e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

rope/refactor/patchedast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def __getslice__(self, i, j):
940940

941941
def _get_number_pattern(self):
942942
# HACK: It is merely an approaximation and does the job
943-
integer = r"\-?(0x[\da-fA-F]+|\d+)"
943+
integer = r"\-?(0[xo][\da-fA-F]+|\d+)"
944944
return r"(%s(\.\d*)?|(\.\d+))([eE][-+]?\d+)?[jJ]?" % integer
945945

946946
_string_pattern = None

ropetest/refactor/patchedasttest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,14 @@ def test_hex_integer_literals_and_region(self):
9494
checker.check_region("Num", start, start + 3)
9595

9696
def test_octal_integer_literals_and_region(self):
97-
source = "a = -0125e1\n"
97+
source = "a = -0o1251\n"
9898
ast_frag = patchedast.get_patched_ast(source, True)
9999
checker = _ResultChecker(self, ast_frag)
100-
start = source.index("-0125e1") + 1
100+
start = source.index("-0o1251") + 1
101101
end = start + 6
102102
# Python 3 parses as UnaryOp(op=USub(), operand=Num(n=10))
103103
checker.check_region("Num", start, end)
104+
checker.check_children("Num", ["0o1251"])
104105

105106
def test_integer_literals_and_sorted_children(self):
106107
source = "a = 10\n"

0 commit comments

Comments
 (0)