Skip to content

Commit 5ea9010

Browse files
authored
gh-133117: Run mypy on tomllib in CI (#133118)
1 parent fd0f5d0 commit 5ea9010

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

.github/workflows/mypy.yml

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- "Lib/_colorize.py"
1212
- "Lib/_pyrepl/**"
1313
- "Lib/test/libregrtest/**"
14+
- "Lib/tomllib/**"
1415
- "Misc/mypy/**"
1516
- "Tools/build/generate_sbom.py"
1617
- "Tools/cases_generator/**"
@@ -44,6 +45,7 @@ jobs:
4445
target: [
4546
"Lib/_pyrepl",
4647
"Lib/test/libregrtest",
48+
"Lib/tomllib",
4749
"Tools/build",
4850
"Tools/cases_generator",
4951
"Tools/clinic",

Lib/tomllib/_parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def get_or_create_nest(
282282
cont = cont[-1]
283283
if not isinstance(cont, dict):
284284
raise KeyError("There is no nest behind this key")
285-
return cont
285+
return cont # type: ignore[no-any-return]
286286

287287
def append_nest_to_list(self, key: Key) -> None:
288288
cont = self.get_or_create_nest(key[:-1])
@@ -741,7 +741,7 @@ def make_safe_parse_float(parse_float: ParseFloat) -> ParseFloat:
741741
instead of returning illegal types.
742742
"""
743743
# The default `float` callable never returns illegal types. Optimize it.
744-
if parse_float is float: # type: ignore[comparison-overlap]
744+
if parse_float is float:
745745
return float
746746

747747
def safe_parse_float(float_str: str) -> Any:

Lib/tomllib/mypy.ini

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Config file for running mypy on tomllib.
2+
# Run mypy by invoking `mypy --config-file Lib/tomllib/mypy.ini`
3+
# on the command-line from the repo root
4+
5+
[mypy]
6+
files = Lib/tomllib
7+
mypy_path = $MYPY_CONFIG_FILE_DIR/../../Misc/mypy
8+
explicit_package_bases = True
9+
python_version = 3.12
10+
pretty = True
11+
12+
# Enable most stricter settings
13+
enable_error_code = ignore-without-code
14+
strict = True
15+
strict_bytes = True
16+
local_partial_types = True
17+
warn_unreachable = True
18+
# TODO(@sobolevn): remove this setting and refactor any found problems
19+
disallow_any_generics = False

Misc/mypy/tomllib

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Lib/tomllib

Misc/mypy/typed-stdlib.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
_colorize.py
44
_pyrepl
5+
tomllib

0 commit comments

Comments
 (0)