| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| 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 |
|---|---|---|
| Expand Up | @@ -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: | ||
| Expand Down Expand Up | @@ -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: | ||
| Expand All | @@ -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] | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThe type ignore here might hide potential type errors. It would be better to ensure that the return type is always a dict[str, Any] or refactor the code to handle other return types explicitly. Consider adding a check to ensure that cont is indeed a dictionary before returning it, and raise a more informative error if it is not.[^1] if not isinstance(cont, dict):
raise TypeError("Expected a dictionary, but got {type(cont)}")
return cont
Sorry, something went wrong.
All reactions
|
||
|
|
||
| def append_nest_to_list(self, key: Key) -> None: | ||
| cont = self.get_or_create_nest(key[:-1]) | ||
| Expand Down Expand Up | @@ -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): | ||
| Expand All | @@ -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() | ||
| Expand Down Expand Up | @@ -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: | ||
| Expand Down | ||
| 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 |
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityConsider 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]
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.