Skip to content

Commit d8e02ba

Browse files
committed
Fix ty diagnostics
1 parent 87cdd90 commit d8e02ba

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ skip = ".git,*.lock,tests,docs/cli-reference,CHANGELOG.md,docs/changelog.md,docs
227227
[tool.ty]
228228
src.include = [ "src" ]
229229
environment.python-version = "3.10"
230-
rules.deprecated = "ignore"
230+
rules.deprecated = "warn"
231231

232232
[tool.pytest]
233233
ini_options.norecursedirs = [ ".hypothesis", ".tox", "tests/data/*" ]

src/datamodel_code_generator/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def validate_each_item(each_item: _HttpKeyValueInput) -> _HttpKeyValuePair:
301301

302302

303303
@lru_cache(maxsize=1)
304-
def _get_config_class() -> type:
304+
def _get_config_class() -> type[Config]:
305305
from pydantic import ConfigDict, Field, ValidationInfo, field_validator, model_validator # noqa: PLC0415
306306
from typing_extensions import Self # noqa: PLC0415
307307

@@ -1159,7 +1159,7 @@ def run_generate_from_config( # noqa: PLR0913, PLR0917
11591159
)
11601160
return generate(
11611161
input_=input_,
1162-
config=cast("Any", generation_config),
1162+
config=generation_config,
11631163
)
11641164

11651165

src/datamodel_code_generator/parser/jsonschema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888

8989
if TYPE_CHECKING:
9090
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
91+
from typing import TypeGuard
9192

9293
from datamodel_code_generator._types import JSONSchemaParserConfigDict
9394
from datamodel_code_generator.config import JSONSchemaParserConfig
@@ -3614,7 +3615,7 @@ def parse_one_of(self, name: str, obj: JsonSchemaObject, path: list[str]) -> lis
36143615
"""Parse oneOf schema into a list of data types."""
36153616
return self.parse_combined_schema(name, obj, path, "oneOf")
36163617

3617-
def _is_required_only_schema(self, item: JsonSchemaObject | bool) -> bool: # noqa: FBT001
3618+
def _is_required_only_schema(self, item: JsonSchemaObject | bool) -> TypeGuard[JsonSchemaObject]: # noqa: FBT001
36183619
"""Return whether a combined-schema branch is only a property presence rule."""
36193620
if not isinstance(item, JsonSchemaObject):
36203621
return False

src/datamodel_code_generator/parser/openapi.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ class OpenAPIParser(JsonSchemaParser):
203203
"""Parser for OpenAPI 2.0/3.0/3.1/3.2 and Swagger specifications."""
204204

205205
SCHEMA_PATHS: ClassVar[list[str]] = ["#/components/schemas"]
206+
config: OpenAPIParserConfig
206207

207208
@cached_property
208209
def schema_features(self) -> OpenAPISchemaFeatures:
@@ -233,11 +234,11 @@ def __init__(
233234
if config is None and options.get("wrap_string_literal") is None:
234235
options["wrap_string_literal"] = False
235236
super().__init__(source=source, config=config, **options)
236-
self.open_api_scopes: list[OpenAPIScope] = self.config.openapi_scopes or [OpenAPIScope.Schemas] # ty: ignore
237-
self.include_path_parameters: bool = self.config.include_path_parameters # ty: ignore
238-
self.use_status_code_in_response_name: bool = self.config.use_status_code_in_response_name # ty: ignore
239-
self.openapi_include_paths: list[str] | None = self.config.openapi_include_paths # ty: ignore
240-
self.openapi_include_info_version: bool = self.config.openapi_include_info_version # ty: ignore
237+
self.open_api_scopes: list[OpenAPIScope] = self.config.openapi_scopes or [OpenAPIScope.Schemas]
238+
self.include_path_parameters: bool = self.config.include_path_parameters
239+
self.use_status_code_in_response_name: bool = self.config.use_status_code_in_response_name
240+
self.openapi_include_paths: list[str] | None = self.config.openapi_include_paths
241+
self.openapi_include_info_version: bool = self.config.openapi_include_info_version
241242
self.openapi_info_version: str | None = None
242243
if self.openapi_include_paths and OpenAPIScope.Paths not in self.open_api_scopes:
243244
warn(

tests/main/test_main_general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def test_run_generate_from_config_generate_kwargs_are_pinned() -> None:
738738
"""Pin the validated CLI Config values overlaid before generate() runs."""
739739
assert _run_generate_from_config_generate_kwargs() == snapshot([
740740
("input_", "input_"),
741-
("config", "cast('Any', generation_config)"),
741+
("config", "generation_config"),
742742
])
743743
assert _run_generate_from_config_model_copy_updates() == snapshot([
744744
("input_filename", "None"),

0 commit comments

Comments
 (0)