Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce import time part 3: remove typing import #251

Merged
merged 4 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading