From 3eec25a05ed2511e4b102ffd10f8aa9e695ad085 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 29 Apr 2025 13:09:23 +0300 Subject: [PATCH] gh-133117: Run mypy on `tomllib` in CI --- .github/workflows/mypy.yml | 2 ++ Lib/tomllib/_parser.py | 4 ++-- Lib/tomllib/mypy.ini | 19 +++++++++++++++++++ Misc/mypy/tomllib | 1 + Misc/mypy/typed-stdlib.txt | 1 + 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 Lib/tomllib/mypy.ini create mode 120000 Misc/mypy/tomllib diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 212f3e8d70c836..77283edbf47814 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -10,6 +10,7 @@ on: - ".github/workflows/mypy.yml" - "Lib/_pyrepl/**" - "Lib/test/libregrtest/**" + - "Lib/tomllib/**" - "Tools/build/generate_sbom.py" - "Tools/cases_generator/**" - "Tools/clinic/**" @@ -42,6 +43,7 @@ jobs: target: [ "Lib/_pyrepl", "Lib/test/libregrtest", + "Lib/tomllib", "Tools/build", "Tools/cases_generator", "Tools/clinic", diff --git a/Lib/tomllib/_parser.py b/Lib/tomllib/_parser.py index 0e522c3a69e6fe..da56af3f34d9b2 100644 --- a/Lib/tomllib/_parser.py +++ b/Lib/tomllib/_parser.py @@ -282,7 +282,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] def append_nest_to_list(self, key: Key) -> None: cont = self.get_or_create_nest(key[:-1]) @@ -741,7 +741,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: diff --git a/Lib/tomllib/mypy.ini b/Lib/tomllib/mypy.ini new file mode 100644 index 00000000000000..0297d19e2c8445 --- /dev/null +++ b/Lib/tomllib/mypy.ini @@ -0,0 +1,19 @@ +# 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 +# TODO(@sobolevn): remove this setting and refactor any found problems +disallow_any_generics = False \ No newline at end of file diff --git a/Misc/mypy/tomllib b/Misc/mypy/tomllib new file mode 120000 index 00000000000000..20f34d49da0cd4 --- /dev/null +++ b/Misc/mypy/tomllib @@ -0,0 +1 @@ +../../Lib/tomllib \ No newline at end of file diff --git a/Misc/mypy/typed-stdlib.txt b/Misc/mypy/typed-stdlib.txt index 8cd6858b4e591e..9b27ee0d2de077 100644 --- a/Misc/mypy/typed-stdlib.txt +++ b/Misc/mypy/typed-stdlib.txt @@ -2,3 +2,4 @@ _colorize.py _pyrepl +tomllib \ No newline at end of file