Skip to content

Commit

Permalink
Fix parsing of octal literal by patchedast
Browse files Browse the repository at this point in the history
  • Loading branch information
lieryan committed Dec 22, 2022
1 parent 4293428 commit 4a9e32e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rope/refactor/patchedast.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def __getslice__(self, i, j):

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

_string_pattern = None
Expand Down
5 changes: 3 additions & 2 deletions ropetest/refactor/patchedasttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ def test_hex_integer_literals_and_region(self):
checker.check_region("Num", start, start + 3)

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

def test_integer_literals_and_sorted_children(self):
source = "a = 10\n"
Expand Down

0 comments on commit 4a9e32e

Please sign in to comment.