Skip to content

Commit 6fadf30

Browse files
authored
chore: adjust typing to be ready for next mypy release (#1088)
This types better on 1.16 (will need a few more adjustments when it comes out, but this is closer). See hauntsaninja/mypy_primer#174 and python/mypy#19139. Signed-off-by: Henry Schreiner <[email protected]>
1 parent 25e07d5 commit 6fadf30

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
exclude: "^tests"
2626

2727
- repo: https://github.com/astral-sh/ruff-pre-commit
28-
rev: v0.11.8
28+
rev: v0.11.11
2929
hooks:
3030
- id: ruff
3131
args: ["--fix", "--show-fixes"]
@@ -131,7 +131,7 @@ repos:
131131
additional_dependencies: [cogapp]
132132

133133
- repo: https://github.com/henryiii/validate-pyproject-schema-store
134-
rev: 2025.04.28
134+
rev: 2025.05.12
135135
hooks:
136136
- id: validate-pyproject
137137

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ exclude = [
174174
'^tests/packages/simplest_c/src/simplest/__init__.py',
175175
'^tests/packages/dynamic_metadata/src/dynamic/__init__.py',
176176
'^tests/packages/.*/setup.py',
177+
'^tests/packages/extensionlib/*',
177178
]
178179
mypy_path = ["$MYPY_CONFIG_FILE_DIR/src", "$MYPY_CONFIG_FILE_DIR/tests/utils"]
179180
python_version = "3.8"

src/scikit_build_core/file_api/reply.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _convert_any(self, item: Any, target: Type[T]) -> T: ...
9393
def _convert_any(self, item: Any, target: Any) -> Any: ...
9494

9595
def _convert_any(self, item: Any, target: Union[Type[T], Any]) -> Any:
96-
if isinstance(target, type) and dataclasses.is_dataclass(target):
96+
if dataclasses.is_dataclass(target) and isinstance(target, type):
9797
# We don't have DataclassInstance exposed in typing yet
9898
return self.make_class(item, target)
9999
origin = get_origin(target)
@@ -103,7 +103,7 @@ def _convert_any(self, item: Any, target: Union[Type[T], Any]) -> Any:
103103
if origin is Union:
104104
return self._convert_any(item, get_args(target)[0])
105105

106-
return target(item)
106+
return target(item) # type: ignore[call-arg]
107107

108108

109109
def load_reply_dir(path: Path) -> Index:

src/scikit_build_core/settings/documentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ def mk_docs(dc: type[object], prefix: str = "") -> Generator[DCDoc, None, None]:
101101

102102
for field in dataclasses.fields(dc):
103103
field_type = field.type
104-
if isinstance(field_type, type) and dataclasses.is_dataclass(field_type):
104+
if dataclasses.is_dataclass(field_type) and isinstance(field_type, type):
105105
yield from mk_docs(field_type, prefix=f"{prefix}{field.name}.")
106106
continue
107107

108108
if get_origin(field.type) is list:
109109
field_type = get_args(field.type)[0]
110-
if isinstance(field_type, type) and dataclasses.is_dataclass(field_type):
110+
if dataclasses.is_dataclass(field_type) and isinstance(field_type, type):
111111
yield from mk_docs(field_type, prefix=f"{prefix}{field.name}[].")
112112
continue
113113

src/scikit_build_core/settings/json_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def to_json_schema(dclass: type[Any], *, normalize_keys: bool) -> dict[str, Any]
3030
required = []
3131
for field in dataclasses.fields(dclass):
3232
field_type = field.type
33-
if isinstance(field_type, type) and dataclasses.is_dataclass(field.type):
33+
if dataclasses.is_dataclass(field.type) and isinstance(field_type, type):
3434
props[field.name] = to_json_schema(
3535
field_type, normalize_keys=normalize_keys
3636
)
@@ -113,7 +113,7 @@ def to_json_schema(dclass: type[Any], *, normalize_keys: bool) -> dict[str, Any]
113113

114114

115115
def convert_type(t: Any, *, normalize_keys: bool) -> dict[str, Any]:
116-
if isinstance(t, type) and dataclasses.is_dataclass(t):
116+
if dataclasses.is_dataclass(t) and isinstance(t, type):
117117
return to_json_schema(t, normalize_keys=normalize_keys)
118118
if t is str or t is Path or t is Version or t is SpecifierSet:
119119
return {"type": "string"}

src/scikit_build_core/settings/sources.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _nested_dataclass_to_names(
158158
Yields each entry, like ``("a", "b", "c")`` for ``a.b.c``.
159159
"""
160160

161-
if isinstance(target, type) and dataclasses.is_dataclass(target):
161+
if dataclasses.is_dataclass(target) and isinstance(target, type):
162162
for field in dataclasses.fields(target):
163163
yield from _nested_dataclass_to_names(field.type, *inner, field.name)
164164
else:
@@ -324,7 +324,7 @@ def _unrecognized_dict(
324324
continue
325325
(inner_option_field,) = matches
326326
inner_option = inner_option_field.type
327-
if isinstance(inner_option, type) and dataclasses.is_dataclass(inner_option):
327+
if dataclasses.is_dataclass(inner_option) and isinstance(inner_option, type):
328328
yield from _unrecognized_dict(
329329
settings[keystr], inner_option, (*above, keystr)
330330
)
@@ -492,7 +492,7 @@ def convert(cls, item: Any, target: type[Any] | Any) -> object:
492492
"""
493493
target, annotations = _process_annotated(target)
494494
raw_target = _get_target_raw_type(target)
495-
if isinstance(raw_target, type) and dataclasses.is_dataclass(raw_target):
495+
if dataclasses.is_dataclass(raw_target) and isinstance(raw_target, type):
496496
fields = dataclasses.fields(raw_target)
497497
values = ((k.replace("-", "_"), v) for k, v in item.items())
498498
return raw_target(
@@ -581,7 +581,7 @@ def convert_target(self, target: type[T], *prefixes: str) -> T:
581581
errors = []
582582
prep: dict[str, Any] = {}
583583
for field in dataclasses.fields(target): # type: ignore[arg-type]
584-
if isinstance(field.type, type) and dataclasses.is_dataclass(field.type):
584+
if dataclasses.is_dataclass(field.type) and isinstance(field.type, type):
585585
try:
586586
prep[field.name] = self.convert_target(
587587
field.type, *prefixes, field.name

0 commit comments

Comments
 (0)