Skip to content

Commit

Permalink
Reduce import time by removing typing import (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin authored Jan 12, 2025
1 parent 4188188 commit 1da01ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/tomli/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import sys
from types import MappingProxyType
from typing import IO, TYPE_CHECKING, Any, Final, NamedTuple

from ._re import (
RE_DATETIME,
Expand All @@ -17,8 +16,10 @@
match_to_number,
)

TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Iterable
from typing import IO, Any, Final

from ._types import Key, ParseFloat, Pos

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

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


class Output(NamedTuple):
data: NestedDict
flags: Flags
class Output:
def __init__(self) -> None:
self.data = NestedDict()
self.flags = Flags()


def skip_chars(src: str, pos: Pos, chars: Iterable[str]) -> Pos:
Expand Down
4 changes: 3 additions & 1 deletion src/tomli/_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from datetime import date, datetime, time, timedelta, timezone, tzinfo
from functools import lru_cache
import re
from typing import TYPE_CHECKING, Any, Final

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any, Final

from ._types import ParseFloat

# E.g.
Expand Down

0 comments on commit 1da01ef

Please sign in to comment.