Skip to content

Commit f574f36

Browse files
authored
Update mypy to 1.15 and use --strict mode (#257)
1 parent 1da01ef commit f574f36

File tree

9 files changed

+27
-26
lines changed

9 files changed

+27
-26
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ repos:
5454
- flake8-builtins
5555
- flake8-comprehensions
5656
- repo: https://github.com/pre-commit/mirrors-mypy
57-
rev: f56614daa94d5cd733d3b7004c5df9caad267b4a # frozen: v1.13.0
57+
rev: f40886d54c729f533f864ed6ce584e920feb0af7 # frozen: v1.15.0
5858
hooks:
5959
- id: mypy
6060
args: ["--scripts-are-modules"]

pyproject.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,14 @@ exclude_lines = [
145145
[tool.mypy]
146146
show_error_codes = true
147147
warn_unreachable = true
148-
warn_unused_ignores = true
149-
warn_redundant_casts = true
150-
warn_unused_configs = true
151-
# Disabling incremental mode is required for `warn_unused_configs = true` to work
148+
strict = true
149+
strict_bytes = true
150+
local_partial_types = true
151+
# Disabling incremental mode is required for `warn_unused_configs = true`
152+
# (implied by `strict = true`) to work
152153
incremental = false
153-
disallow_untyped_defs = true
154-
check_untyped_defs = true
155-
strict_equality = true
156-
implicit_reexport = false
157-
no_implicit_optional = true
154+
155+
enable_error_code = ["ignore-without-code"]
158156

159157
[[tool.mypy.overrides]]
160158
module = "tests.*"

scripts/use_setuptools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def use_setuptools() -> None:
1313
pyproject_path = Path(__file__).parent.parent / "pyproject.toml"
1414
data = tomllib.loads(pyproject_path.read_bytes().decode())
1515
data["build-system"] = {
16-
"requires": ["setuptools>=69", "mypy[mypyc]>=1.13"],
16+
"requires": ["setuptools>=69", "mypy[mypyc]>=1.15"],
1717
"build-backend": "setuptools.build_meta",
1818
}
1919
pyproject_path.write_bytes(tomli_w.dumps(data).encode())

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
if os.environ.get("TOMLI_USE_MYPYC") == "1":
66
import glob
77

8-
from mypyc.build import mypycify # type: ignore[import-untyped]
8+
from mypyc.build import mypycify
99

1010
files = glob.glob("src/**/*.py", recursive=True)
1111
ext_modules = mypycify(files)

src/tomli/_parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class Flags:
226226
EXPLICIT_NEST: Final = 1
227227

228228
def __init__(self) -> None:
229-
self._flags: dict[str, dict] = {}
229+
self._flags: dict[str, dict[Any, Any]] = {}
230230
self._pending_flags: set[tuple[Key, int]] = set()
231231

232232
def add_pending(self, key: Key, flag: int) -> None:
@@ -284,7 +284,7 @@ def get_or_create_nest(
284284
key: Key,
285285
*,
286286
access_lists: bool = True,
287-
) -> dict:
287+
) -> dict[str, Any]:
288288
cont: Any = self.dict
289289
for k in key:
290290
if k not in cont:
@@ -294,7 +294,7 @@ def get_or_create_nest(
294294
cont = cont[-1]
295295
if not isinstance(cont, dict):
296296
raise KeyError("There is no nest behind this key")
297-
return cont
297+
return cont # type: ignore[no-any-return]
298298

299299
def append_nest_to_list(self, key: Key) -> None:
300300
cont = self.get_or_create_nest(key[:-1])
@@ -500,9 +500,9 @@ def parse_one_line_basic_str(src: str, pos: Pos) -> tuple[Pos, str]:
500500

501501
def parse_array(
502502
src: str, pos: Pos, parse_float: ParseFloat, nest_lvl: int
503-
) -> tuple[Pos, list]:
503+
) -> tuple[Pos, list[Any]]:
504504
pos += 1
505-
array: list = []
505+
array: list[Any] = []
506506

507507
pos = skip_comments_and_array_ws(src, pos)
508508
if src.startswith("]", pos):
@@ -526,7 +526,7 @@ def parse_array(
526526

527527
def parse_inline_table(
528528
src: str, pos: Pos, parse_float: ParseFloat, nest_lvl: int
529-
) -> tuple[Pos, dict]:
529+
) -> tuple[Pos, dict[str, Any]]:
530530
pos += 1
531531
nested_dict = NestedDict()
532532
flags = Flags()

src/tomli/_re.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
)
5555

5656

57-
def match_to_datetime(match: re.Match) -> datetime | date:
57+
def match_to_datetime(match: re.Match[str]) -> datetime | date:
5858
"""Convert a `RE_DATETIME` match to `datetime.datetime` or `datetime.date`.
5959
6060
Raises ValueError if the match does not correspond to a valid date
@@ -103,13 +103,13 @@ def cached_tz(hour_str: str, minute_str: str, sign_str: str) -> timezone:
103103
)
104104

105105

106-
def match_to_localtime(match: re.Match) -> time:
106+
def match_to_localtime(match: re.Match[str]) -> time:
107107
hour_str, minute_str, sec_str, micros_str = match.groups()
108108
micros = int(micros_str.ljust(6, "0")) if micros_str else 0
109109
return time(int(hour_str), int(minute_str), int(sec_str), micros)
110110

111111

112-
def match_to_number(match: re.Match, parse_float: ParseFloat) -> Any:
112+
def match_to_number(match: re.Match[str], parse_float: ParseFloat) -> Any:
113113
if match.group("floatpart"):
114114
return parse_float(match.group())
115115
return int(match.group(), 0)

tests/burntsushi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def convert(obj): # noqa: C901
4444
"value": str(obj),
4545
}
4646
elif isinstance(obj, list):
47-
return [convert(i) for i in obj]
47+
return [convert(i) for i in obj] # type: ignore[no-untyped-call]
4848
elif isinstance(obj, dict):
49-
return {k: convert(v) for k, v in obj.items()}
49+
return {k: convert(v) for k, v in obj.items()} # type: ignore[no-untyped-call]
5050
raise Exception("unsupported type")
5151

5252

tests/test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ def test_valid(self):
5959
continue
6060
toml_str = valid.read_bytes().decode()
6161
actual = tomllib.loads(toml_str)
62-
actual = burntsushi.convert(actual)
62+
actual = burntsushi.convert(actual) # type: ignore[no-untyped-call]
6363
expected = burntsushi.normalize(expected)
6464
self.assertEqual(actual, expected)

tests/test_error.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# SPDX-FileCopyrightText: 2021 Taneli Hukkinen
33
# Licensed to PSF under a Contributor Agreement.
44

5+
from __future__ import annotations
6+
7+
from typing import Any
58
import unittest
69

710
from . import tomllib
@@ -57,10 +60,10 @@ def test_type_error(self):
5760
)
5861

5962
def test_invalid_parse_float(self):
60-
def dict_returner(s: str) -> dict:
63+
def dict_returner(s: str) -> dict[Any, Any]:
6164
return {}
6265

63-
def list_returner(s: str) -> list:
66+
def list_returner(s: str) -> list[Any]:
6467
return []
6568

6669
for invalid_parse_float in (dict_returner, list_returner):

0 commit comments

Comments
 (0)