|
6 | 6 |
|
7 | 7 | from types import MappingProxyType |
8 | 8 |
|
| 9 | +__lazy_modules__ = ["tomllib._re"] |
| 10 | + |
| 11 | +from ._re import ( |
| 12 | + RE_DATETIME, |
| 13 | + RE_LOCALTIME, |
| 14 | + RE_NUMBER, |
| 15 | + match_to_datetime, |
| 16 | + match_to_localtime, |
| 17 | + match_to_number, |
| 18 | +) |
| 19 | + |
9 | 20 | TYPE_CHECKING = False |
10 | 21 | if TYPE_CHECKING: |
11 | 22 | from collections.abc import Iterable |
12 | 23 | from typing import IO, Any, Final |
13 | 24 |
|
14 | 25 | from ._types import Key, ParseFloat, Pos |
15 | 26 |
|
16 | | - _REGEX_IMPORTED = True |
17 | | - from ._re import ( |
18 | | - RE_DATETIME, |
19 | | - RE_LOCALTIME, |
20 | | - RE_NUMBER, |
21 | | - match_to_datetime, |
22 | | - match_to_localtime, |
23 | | - match_to_number, |
24 | | - ) |
25 | | -else: |
26 | | - # Regular expressions are lazy imported to speed up startup time |
27 | | - _REGEX_IMPORTED = False |
28 | | - |
29 | 27 | ASCII_CTRL: Final = frozenset(chr(i) for i in range(32)) | frozenset(chr(127)) |
30 | 28 |
|
31 | 29 | # Neither of these sets include quotation mark or backslash. They are |
@@ -727,24 +725,11 @@ def parse_value( |
727 | 725 | if char == "{": |
728 | 726 | return parse_inline_table(src, pos, parse_float) |
729 | 727 |
|
730 | | - global _REGEX_IMPORTED, RE_DATETIME, RE_LOCALTIME, RE_NUMBER |
731 | | - global match_to_datetime, match_to_localtime, match_to_number |
732 | | - if not _REGEX_IMPORTED: |
733 | | - # Simple number parser avoiding regex |
734 | | - if char in _DECDIGIT_CHARS: |
735 | | - res = _parse_simple_number(src, pos) |
736 | | - if res is not None: |
737 | | - return res |
738 | | - |
739 | | - from ._re import ( |
740 | | - RE_DATETIME, |
741 | | - RE_LOCALTIME, |
742 | | - RE_NUMBER, |
743 | | - match_to_datetime, |
744 | | - match_to_localtime, |
745 | | - match_to_number, |
746 | | - ) |
747 | | - _REGEX_IMPORTED = True |
| 728 | + # Simple number parser avoiding regex |
| 729 | + if char in _DECDIGIT_CHARS: |
| 730 | + res = _parse_simple_number(src, pos) |
| 731 | + if res is not None: |
| 732 | + return res |
748 | 733 |
|
749 | 734 | # Dates and times |
750 | 735 | datetime_match = RE_DATETIME.match(src, pos) |
|
0 commit comments