Skip to content

Commit 77d8502

Browse files
committed
Reduce import time part 3: remove typing import
1 parent 4188188 commit 77d8502

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/tomli/_parser.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import sys
88
from types import MappingProxyType
9-
from typing import IO, TYPE_CHECKING, Any, Final, NamedTuple
109

1110
from ._re import (
1211
RE_DATETIME,
@@ -17,8 +16,10 @@
1716
match_to_number,
1817
)
1918

20-
if TYPE_CHECKING:
19+
MYPY = False
20+
if MYPY:
2121
from collections.abc import Iterable
22+
from typing import IO, Any, Final
2223

2324
from ._types import Key, ParseFloat, Pos
2425

@@ -156,7 +157,7 @@ def loads(__s: str, *, parse_float: ParseFloat = float) -> dict[str, Any]: # no
156157
f"Expected str object, not '{type(__s).__qualname__}'"
157158
) from None
158159
pos = 0
159-
out = Output(NestedDict(), Flags())
160+
out = Output()
160161
header: Key = ()
161162
parse_float = make_safe_parse_float(parse_float)
162163

@@ -307,9 +308,10 @@ def append_nest_to_list(self, key: Key) -> None:
307308
cont[last_key] = [{}]
308309

309310

310-
class Output(NamedTuple):
311-
data: NestedDict
312-
flags: Flags
311+
class Output:
312+
def __init__(self) -> None:
313+
self.data: Final = NestedDict()
314+
self.flags: Final = Flags()
313315

314316

315317
def skip_chars(src: str, pos: Pos, chars: Iterable[str]) -> Pos:

src/tomli/_re.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
from datetime import date, datetime, time, timedelta, timezone, tzinfo
88
from functools import lru_cache
99
import re
10-
from typing import TYPE_CHECKING, Any, Final
1110

12-
if TYPE_CHECKING:
11+
MYPY = False
12+
if MYPY:
13+
from typing import Any, Final
14+
1315
from ._types import ParseFloat
1416

1517
# E.g.

0 commit comments

Comments
 (0)