Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-118761: Improve import time of tomllib#128907
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,11 +4,7 @@ | ||
| from __future__ import annotations | ||
| from collections.abc import Iterable | ||
| import string | ||
| from types import MappingProxyType | ||
| from typing import Any, BinaryIO, NamedTuple | ||
| import warnings | ||
| from ._re import ( | ||
| RE_DATETIME, | ||
| @@ -18,7 +14,13 @@ | ||
| match_to_localtime, | ||
| match_to_number, | ||
| ) | ||
| from ._types import Key, ParseFloat, Pos | ||
| TYPE_CHECKING = False | ||
| if TYPE_CHECKING: | ||
| from collections.abc import Iterable | ||
| from typing import IO, Any | ||
| from ._types import Key, ParseFloat, Pos | ||
| ASCII_CTRL = frozenset(chr(i) for i in range(32)) | frozenset(chr(127)) | ||
| @@ -34,9 +36,11 @@ | ||
| TOML_WS = frozenset(" \t") | ||
| TOML_WS_AND_NEWLINE = TOML_WS | frozenset("\n") | ||
| BARE_KEY_CHARS = frozenset(string.ascii_letters + string.digits + "-_") | ||
| BARE_KEY_CHARS = frozenset( | ||
| "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "-_" | ||
| ) | ||
| KEY_INITIAL_CHARS = BARE_KEY_CHARS | frozenset("\"'") | ||
| HEXDIGIT_CHARS = frozenset(string.hexdigits) | ||
| HEXDIGIT_CHARS = frozenset("abcdef" "ABCDEF" "0123456789") | ||
| BASIC_STR_ESCAPE_REPLACEMENTS = MappingProxyType( | ||
| { | ||
| @@ -80,6 +84,8 @@ def __init__( | ||
| or not isinstance(doc, str) | ||
| or not isinstance(pos, int) | ||
| ): | ||
| import warnings | ||
| warnings.warn( | ||
| "Free-form arguments for TOMLDecodeError are deprecated. " | ||
| "Please set 'msg' (str), 'doc' (str) and 'pos' (int) arguments only.", | ||
| @@ -115,7 +121,7 @@ def __init__( | ||
| self.colno = colno | ||
| def load(fp: BinaryIO, /, *, parse_float: ParseFloat = float) -> dict[str, Any]: | ||
| def load(fp: IO[bytes], /, *, parse_float: ParseFloat = float) -> dict[str, Any]: | ||
| """Parse TOML from a binary file object.""" | ||
| b = fp.read() | ||
| try: | ||
| @@ -139,7 +145,7 @@ def loads(s: str, /, *, parse_float: ParseFloat = float) -> dict[str, Any]: # n | ||
| 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) | ||
| @@ -290,9 +296,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() | ||
AA-Turner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| def skip_chars(src: str, pos: Pos, chars: Iterable[str]) -> Pos: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions 2 Misc/NEWS.d/next/Library/2025-01-16-10-06-40.gh-issue-118761.z100LC.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Improve import time of :mod:`tomllib` by removing ``typing``, ``string``, | ||
| and ``tomllib._types`` imports. Patch by Taneli Hukkinen. |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.