-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update tomllib from 3.13.5 #5902
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import unittest | ||
|
||
from test.test_tomllib import load_tests | ||
from . import load_tests | ||
|
||
|
||
unittest.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ class Flags: | |
EXPLICIT_NEST = 1 | ||
|
||
def __init__(self) -> None: | ||
self._flags: dict[str, dict] = {} | ||
self._flags: dict[str, dict[Any, Any]] = {} | ||
self._pending_flags: set[tuple[Key, int]] = set() | ||
|
||
def add_pending(self, key: Key, flag: int) -> None: | ||
|
@@ -200,7 +200,7 @@ def get_or_create_nest( | |
key: Key, | ||
*, | ||
access_lists: bool = True, | ||
) -> dict: | ||
) -> dict[str, Any]: | ||
cont: Any = self.dict | ||
for k in key: | ||
if k not in cont: | ||
|
@@ -210,7 +210,7 @@ def get_or_create_nest( | |
cont = cont[-1] | ||
if not isinstance(cont, dict): | ||
raise KeyError("There is no nest behind this key") | ||
return cont | ||
return cont # type: ignore[no-any-return] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type ignore here might hide potential type errors. It would be better to ensure that the return type is always a if not isinstance(cont, dict):
raise TypeError("Expected a dictionary, but got {type(cont)}")
return cont |
||
|
||
def append_nest_to_list(self, key: Key) -> None: | ||
cont = self.get_or_create_nest(key[:-1]) | ||
|
@@ -409,9 +409,9 @@ def parse_one_line_basic_str(src: str, pos: Pos) -> tuple[Pos, str]: | |
return parse_basic_str(src, pos, multiline=False) | ||
|
||
|
||
def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list]: | ||
def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list[Any]]: | ||
pos += 1 | ||
array: list = [] | ||
array: list[Any] = [] | ||
|
||
pos = skip_comments_and_array_ws(src, pos) | ||
if src.startswith("]", pos): | ||
|
@@ -433,7 +433,7 @@ def parse_array(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, list] | |
return pos + 1, array | ||
|
||
|
||
def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, dict]: | ||
def parse_inline_table(src: str, pos: Pos, parse_float: ParseFloat) -> tuple[Pos, dict[str, Any]]: | ||
pos += 1 | ||
nested_dict = NestedDict() | ||
flags = Flags() | ||
|
@@ -679,7 +679,7 @@ def make_safe_parse_float(parse_float: ParseFloat) -> ParseFloat: | |
instead of returning illegal types. | ||
""" | ||
# The default `float` callable never returns illegal types. Optimize it. | ||
if parse_float is float: # type: ignore[comparison-overlap] | ||
if parse_float is float: | ||
return float | ||
|
||
def safe_parse_float(float_str: str) -> Any: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Config file for running mypy on tomllib. | ||
# Run mypy by invoking `mypy --config-file Lib/tomllib/mypy.ini` | ||
# on the command-line from the repo root | ||
|
||
[mypy] | ||
files = Lib/tomllib | ||
mypy_path = $MYPY_CONFIG_FILE_DIR/../../Misc/mypy | ||
explicit_package_bases = True | ||
python_version = 3.12 | ||
pretty = True | ||
|
||
# Enable most stricter settings | ||
enable_error_code = ignore-without-code | ||
strict = True | ||
strict_bytes = True | ||
local_partial_types = True | ||
warn_unreachable = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using
typing.TypedDict
for more explicit type safety, especially since the keys in this dictionary are known and fixed. This can help catch errors during development.[^1]