Skip to content

Commit 63fd2b1

Browse files
committed
Use public names
1 parent ce57c76 commit 63fd2b1

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Lib/test/test_tomllib/test_misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_types_import(self):
129129
importlib.import_module(f"{tomllib.__name__}._types")
130130

131131
def test_parse_simple_number(self):
132-
parse_simple_number = tomllib._parser._parse_simple_number
132+
parse_simple_number = tomllib._parser.parse_simple_number
133133
self.assertEqual(parse_simple_number("123", 0), (3, 123))
134134
self.assertEqual(parse_simple_number("123\n", 0), (3, 123))
135135
self.assertEqual(parse_simple_number("123 456", 0), (3, 123))
@@ -158,7 +158,7 @@ def test_parse_simple_number(self):
158158
self.assertIsNone(parse_simple_number("b100\n", 0))
159159

160160
def test_lazy_import(self):
161-
# Test that _parse_simple_number() can parse the TOML file without
161+
# Test that parse_simple_number() can parse the TOML file without
162162
# importing regular expressions (tomllib._re)
163163
filename = os_helper.TESTFN
164164
self.addCleanup(os_helper.unlink, filename)

Lib/tomllib/_parser.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
)
4242
KEY_INITIAL_CHARS: Final = BARE_KEY_CHARS | frozenset("\"'")
4343
HEXDIGIT_CHARS: Final = frozenset("abcdef" "ABCDEF" "0123456789")
44-
_DECDIGIT_CHARS: Final = frozenset("0123456789")
45-
_NUMBER_INITIAL_CHARS: Final = _DECDIGIT_CHARS | frozenset("+-")
46-
_NUMBER_END_CHARS: Final = frozenset(",]}") | TOML_WS_AND_NEWLINE
44+
DECDIGIT_CHARS: Final = frozenset("0123456789")
45+
NUMBER_INITIAL_CHARS: Final = DECDIGIT_CHARS | frozenset("+-")
46+
NUMBER_END_CHARS: Final = frozenset(",]}") | TOML_WS_AND_NEWLINE
4747

4848
BASIC_STR_ESCAPE_REPLACEMENTS: Final = frozendict( # type: ignore[name-defined]
4949
{
@@ -668,17 +668,18 @@ def parse_basic_str(src: str, pos: Pos, *, multiline: bool) -> tuple[Pos, str]:
668668
pos += 1
669669

670670

671-
def _parse_simple_number(
671+
# Sub-set of RE_NUMBER: only support decimal integer without "_" separator
672+
def parse_simple_number(
672673
src: str, pos: Pos
673674
) -> None | tuple[Pos, int]:
674675
start = pos
675676
end = len(src)
676-
end_chars = _NUMBER_END_CHARS
677+
end_chars = NUMBER_END_CHARS
677678
if src[pos] in '+-':
678679
pos += 1
679680
if pos >= end:
680681
return None
681-
if src[pos] not in _DECDIGIT_CHARS:
682+
if src[pos] not in DECDIGIT_CHARS:
682683
return None
683684

684685
if src[pos] == '0':
@@ -687,7 +688,7 @@ def _parse_simple_number(
687688
return None
688689
return pos, 0
689690

690-
while src[pos] in _DECDIGIT_CHARS:
691+
while src[pos] in DECDIGIT_CHARS:
691692
pos += 1
692693
if pos >= end:
693694
break
@@ -737,8 +738,8 @@ def parse_value(
737738

738739
# First try a simple number parser which defers import tomllib._re
739740
# to speed up tomllib import time
740-
if char in _NUMBER_INITIAL_CHARS:
741-
res = _parse_simple_number(src, pos)
741+
if char in NUMBER_INITIAL_CHARS:
742+
res = parse_simple_number(src, pos)
742743
if res is not None:
743744
return res
744745

0 commit comments

Comments
 (0)