|
4 | 4 |
|
5 | 5 | from __future__ import annotations |
6 | 6 |
|
7 | | -from collections.abc import Iterable |
8 | | -import string |
9 | 7 | import sys |
10 | 8 | from types import MappingProxyType |
11 | | -from typing import IO, Any, Final, NamedTuple |
12 | | -import warnings |
| 9 | +from typing import IO, TYPE_CHECKING, Any, Final, NamedTuple |
13 | 10 |
|
14 | 11 | from ._re import ( |
15 | 12 | RE_DATETIME, |
|
19 | 16 | match_to_localtime, |
20 | 17 | match_to_number, |
21 | 18 | ) |
22 | | -from ._types import Key, ParseFloat, Pos |
| 19 | + |
| 20 | +if TYPE_CHECKING: |
| 21 | + from collections.abc import Iterable |
| 22 | + |
| 23 | + from ._types import Key, ParseFloat, Pos |
23 | 24 |
|
24 | 25 | # Inline tables/arrays are implemented using recursion. Pathologically |
25 | 26 | # nested documents cause pure Python to raise RecursionError (which is OK), |
|
46 | 47 |
|
47 | 48 | TOML_WS: Final = frozenset(" \t") |
48 | 49 | TOML_WS_AND_NEWLINE: Final = TOML_WS | frozenset("\n") |
49 | | -BARE_KEY_CHARS: Final = frozenset(string.ascii_letters + string.digits + "-_") |
| 50 | +BARE_KEY_CHARS: Final = frozenset( |
| 51 | + "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "-_" |
| 52 | +) |
50 | 53 | KEY_INITIAL_CHARS: Final = BARE_KEY_CHARS | frozenset("\"'") |
51 | | -HEXDIGIT_CHARS: Final = frozenset(string.hexdigits) |
| 54 | +HEXDIGIT_CHARS: Final = frozenset("abcdef" "ABCDEF" "0123456789") |
52 | 55 |
|
53 | 56 | BASIC_STR_ESCAPE_REPLACEMENTS: Final = MappingProxyType( |
54 | 57 | { |
@@ -92,6 +95,8 @@ def __init__( |
92 | 95 | or not isinstance(doc, str) |
93 | 96 | or not isinstance(pos, int) |
94 | 97 | ): |
| 98 | + import warnings |
| 99 | + |
95 | 100 | warnings.warn( |
96 | 101 | "Free-form arguments for TOMLDecodeError are deprecated. " |
97 | 102 | "Please set 'msg' (str), 'doc' (str) and 'pos' (int) arguments only.", |
|
0 commit comments