Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/datamodel_code_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ def run_generate_from_config( # noqa: PLR0913, PLR0917
)
return generate(
input_=input_,
config=generation_config,
config=cast("Any", generation_config), # ty: ignore[redundant-cast]
)


Expand Down
2 changes: 1 addition & 1 deletion src/datamodel_code_generator/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def generate_dynamic_models(
while len(_dynamic_models_cache) >= cache_size:
oldest_key = next(iter(_dynamic_models_cache))
del _dynamic_models_cache[oldest_key]
_dynamic_models_cache[cache_key] = models # type: ignore[index]
_dynamic_models_cache[cache_key] = models # ty: ignore[invalid-assignment]

return _filter_target_models(models, normalized_target_model_names)

Expand Down
10 changes: 5 additions & 5 deletions src/datamodel_code_generator/input_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def _try_rebuild_model(obj: type) -> None:
"StrictTypes": StrictTypes,
"UnionMode": UnionMode,
}
obj.model_rebuild(_types_namespace=types_namespace) # ty: ignore
obj.model_rebuild(_types_namespace=types_namespace) # ty: ignore[unresolved-attribute]
elif module == "datamodel_code_generator.__main__" and class_name in main_config_classes: # pragma: no cover
from datamodel_code_generator.enums import UnionMode # noqa: PLC0415
from datamodel_code_generator.types import StrictTypes # noqa: PLC0415
Expand All @@ -678,9 +678,9 @@ def _try_rebuild_model(obj: type) -> None:
"UnionMode": UnionMode,
"StrictTypes": StrictTypes,
}
obj.model_rebuild(_types_namespace=types_namespace) # ty: ignore
obj.model_rebuild(_types_namespace=types_namespace) # ty: ignore[unresolved-attribute]
else:
obj.model_rebuild() # ty: ignore
obj.model_rebuild() # ty: ignore[unresolved-attribute]


def _get_base_model_parents(model_class: type) -> list[type]:
Expand Down Expand Up @@ -827,7 +827,7 @@ def load_model_schema( # noqa: PLR0912, PLR0914, PLR0915
model_name = model_class.__name__
_try_rebuild_model(model_class)

schema = model_class.model_json_schema(schema_generator=schema_generator) # ty: ignore
schema = model_class.model_json_schema(schema_generator=schema_generator) # ty: ignore[unresolved-attribute]
schema = _add_python_type_for_unserializable(schema, model_class)
schema = _add_python_type_info(schema, model_class)

Expand Down Expand Up @@ -923,7 +923,7 @@ def _load_single_model_schema( # noqa: PLR0912, PLR0915
if ref_strategy and ref_strategy != InputModelRefStrategy.RegenerateAll:
nested_models = _collect_nested_models(obj)
model_name = getattr(obj, "__name__", None)
if model_name and "$defs" in schema and model_name in schema["$defs"]: # pragma: no cover # ty: ignore
if model_name and "$defs" in schema and model_name in schema["$defs"]: # pragma: no cover # ty: ignore[unsupported-operator]
nested_models[model_name] = obj
schema = _filter_defs_by_strategy(schema, nested_models, output_model_type, ref_strategy)

Expand Down
2 changes: 1 addition & 1 deletion src/datamodel_code_generator/model/pydantic_v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ConfigDict(_BaseModel):
use_attribute_docstrings: Optional[bool] = None # noqa: UP045
json_schema_extra: Optional[Dict[str, Any]] = None # noqa: UP006, UP045

def dict(self, **kwargs: Any) -> dict[str, Any]: # type: ignore[override]
def dict(self, **kwargs: Any) -> dict[str, Any]: # ty: ignore[invalid-type-form]
"""Return dict for templates."""
return self.model_dump(**kwargs)

Expand Down
2 changes: 1 addition & 1 deletion src/datamodel_code_generator/model/pydantic_v2/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def get_data_str_type(self, types: Types, **kwargs: Any) -> DataType:
strict = StrictTypes.str in self.strict_types
if data_type_kwargs:
if strict:
data_type_kwargs["strict"] = True # ty: ignore
data_type_kwargs["strict"] = True # ty: ignore[invalid-assignment]
if self.PATTERN_KEY in data_type_kwargs:
data_type_kwargs[self.PATTERN_KEY] = _get_regex_literal(data_type_kwargs[self.PATTERN_KEY])
return self.data_type.from_import(IMPORT_CONSTR, kwargs=data_type_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion src/datamodel_code_generator/parser/asyncapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def __init__(
**options: Unpack[AsyncAPIParserConfigDict],
) -> None:
"""Initialize the AsyncAPI parser."""
super().__init__(source=source, config=config, **options) # type: ignore[arg-type]
super().__init__(source=source, config=config, **options) # ty: ignore[invalid-argument-type]

@property
def schema_features(self) -> OpenAPISchemaFeatures:
Expand Down
8 changes: 4 additions & 4 deletions src/datamodel_code_generator/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ def _create_default_config(cls, options: ParserConfigDict) -> ParserConfigT:
"DataTypeManager": DataTypeManager,
}
)
return config_class.model_validate(options) # type: ignore[return-value]
return config_class.model_validate(options) # ty: ignore[invalid-return-type]

def _create_data_model(self, model_type: type[DataModel] | None = None, **kwargs: Any) -> DataModel:
"""Create data model instance with dataclass_arguments support for DataClass."""
Expand Down Expand Up @@ -1277,7 +1277,7 @@ def __init__( # noqa: PLR0912, PLR0915
raise ValueError(msg)

if config is None:
config = self._create_default_config(options) # ty: ignore
config = self._create_default_config(options) # ty: ignore[invalid-argument-type]

self.config = config

Expand Down Expand Up @@ -2567,7 +2567,7 @@ def __set_default_enum_member(
if data_type.alias:
if isinstance(enum_member, list):
for enum_member_ in enum_member:
enum_member_.alias = data_type.alias # ty: ignore
enum_member_.alias = data_type.alias # ty: ignore[unresolved-attribute]
else:
enum_member.alias = data_type.alias

Expand Down Expand Up @@ -2691,7 +2691,7 @@ def __change_field_name(
resolver._reset_for_reuse(all_class_names.copy()) # noqa: SLF001
source = cast("DataModel", colliding_reference.source)
resolver.exclude_names.add(cast("str", filed_name))
new_class_name = resolver.add(["type"], cast("str", source.class_name)).name # ty: ignore
new_class_name = resolver.add(["type"], cast("str", source.class_name)).name # ty: ignore[redundant-cast]
source.class_name = new_class_name
all_class_names.add(new_class_name)
elif not rename_type:
Expand Down
6 changes: 3 additions & 3 deletions src/datamodel_code_generator/parser/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# graphql-core >=3.2.7 removed TypeResolvers in favor of TypeFields.kind.
# Normalize to a single callable for resolving type kinds.
try: # graphql-core < 3.2.7
graphql_resolver_kind = graphql.type.introspection.TypeResolvers().kind # ty: ignore
graphql_resolver_kind = graphql.type.introspection.TypeResolvers().kind # ty: ignore[unresolved-attribute]
except AttributeError:
graphql_resolver_kind = graphql.type.introspection.TypeFields.kind

Expand Down Expand Up @@ -422,7 +422,7 @@ def parse_object_like(

base_classes = []
if hasattr(obj, "interfaces"):
base_classes = [self.references[i.name] for i in obj.interfaces] # ty: ignore
base_classes = [self.references[i.name] for i in obj.interfaces] # ty: ignore[not-iterable]

data_model_type = self._create_data_model(
reference=self.references[obj.name],
Expand Down Expand Up @@ -505,4 +505,4 @@ def parse_raw(self) -> None:
for next_type in self.parse_order:
for obj in self.support_graphql_types[next_type]:
parser_ = mapper_from_graphql_type_to_parser_method[next_type]
parser_(obj) # ty: ignore
parser_(obj) # ty: ignore[invalid-argument-type]
6 changes: 3 additions & 3 deletions src/datamodel_code_generator/parser/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def parse_object_fields(

result_fields: list[DataModelFieldBase] = []
for field_obj in fields:
field = properties.get(field_obj.original_name) # ty: ignore
field = properties.get(field_obj.original_name) # ty: ignore[invalid-argument-type]

if (
isinstance(field, JsonSchemaObject)
Expand All @@ -503,7 +503,7 @@ def parse_object_fields(
result_fields.append(field_obj)
continue
normalized_discriminator = self._normalize_discriminator(discriminator)
field_obj = self.data_model_field_type(**{ # noqa: PLW2901 # ty: ignore
field_obj = self.data_model_field_type(**{ # noqa: PLW2901 # ty: ignore[invalid-argument-type]
**field_obj.__dict__,
"data_type": new_field_type,
"extras": {**field_obj.extras, "discriminator": normalized_discriminator},
Expand Down Expand Up @@ -723,7 +723,7 @@ def parse_responses(
continue
schema_path = self._media_schema_path(response_path, from_item_schema=media_schema.from_item_schema)
data_type = self._parse_schema_or_ref(response_name, media_schema.schema, schema_path)
data_types[status_code][content_type] = data_type # ty: ignore
data_types[status_code][content_type] = data_type # ty: ignore[invalid-assignment]

return data_types

Expand Down
10 changes: 5 additions & 5 deletions src/datamodel_code_generator/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def dict( # noqa: PLR0913 # pragma: no cover
exclude_none: bool = False,
) -> dict[str, Any]:
return self.model_dump(
include=include, # ty: ignore
include=include, # ty: ignore[invalid-argument-type]
exclude=set(exclude or ()) | self._exclude_fields,
by_alias=by_alias,
exclude_unset=exclude_unset,
Expand Down Expand Up @@ -672,7 +672,7 @@ def current_base_path_context(self, base_path: Path | None) -> Generator[None, N
"""Temporarily set the current base path within a context."""
if base_path:
base_path = (self._base_path / base_path).resolve()
with context_variable(self.set_current_base_path, self.current_base_path, base_path): # ty: ignore
with context_variable(self.set_current_base_path, self.current_base_path, base_path): # ty: ignore[invalid-argument-type]
yield

@contextmanager
Expand All @@ -686,7 +686,7 @@ def base_url_context(self, base_url: str | None) -> Generator[None, None, None]:
this method was previously a no-op.
"""
if self._base_url or (base_url and is_url(base_url)):
with context_variable(self.set_base_url, self.base_url, base_url): # ty: ignore
with context_variable(self.set_base_url, self.base_url, base_url): # ty: ignore[invalid-argument-type]
yield
else:
yield
Expand All @@ -703,7 +703,7 @@ def set_current_root(self, current_root: Sequence[str]) -> None:
@contextmanager
def current_root_context(self, current_root: Sequence[str]) -> Generator[None, None, None]:
"""Temporarily set the current root path within a context."""
with context_variable(self.set_current_root, self.current_root, current_root): # ty: ignore
with context_variable(self.set_current_root, self.current_root, current_root): # ty: ignore[invalid-argument-type]
yield

@property
Expand Down Expand Up @@ -1407,7 +1407,7 @@ def _get_inflect_engine() -> inflect.engine:
@lru_cache(maxsize=4096)
def get_singular_name(name: str, suffix: str = SINGULAR_NAME_SUFFIX) -> str:
"""Convert a plural name to singular form."""
singular_name = _get_inflect_engine().singular_noun(cast("inflect.Word", name)) # ty: ignore
singular_name = _get_inflect_engine().singular_noun(cast("inflect.Word", name)) # ty: ignore[redundant-cast]
if singular_name is False:
singular_name = f"{name}{suffix}"
return singular_name
Expand Down
2 changes: 1 addition & 1 deletion src/datamodel_code_generator/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def walk(
if self.dict_key:
self.dict_key.walk(visitor, visited)

def find_source(self, source_type: type[SourceT]) -> SourceT | None: # ty: ignore
def find_source(self, source_type: type[SourceT]) -> SourceT | None: # ty: ignore[invalid-type-form]
"""Find the first reference source matching the given type from all nested data types."""
for data_type in self.all_data_types:
if not data_type.reference: # pragma: no cover
Expand Down
6 changes: 3 additions & 3 deletions src/datamodel_code_generator/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
def _get_toml_loader() -> Callable[[Any], dict[str, Any]]:
"""Get the TOML parser lazily."""
try:
from tomllib import load as load_toml_data # noqa: PLC0415 # type: ignore[ignoreMissingImports]
from tomllib import load as load_toml_data # noqa: PLC0415 # ty: ignore[unresolved-import]
except ImportError: # pragma: no cover
from tomli import load as load_toml_data # noqa: PLC0415 # type: ignore[ignoreMissingImports]
from tomli import load as load_toml_data # noqa: PLC0415 # ty: ignore[unresolved-import]

return load_toml_data

Expand Down Expand Up @@ -132,7 +132,7 @@ def get_safe_loader() -> type:
except ImportError: # pragma: no cover
from yaml import SafeLoader as _SafeLoader # noqa: PLC0415

class CustomSafeLoader(_SafeLoader): # type: ignore[valid-type,misc]
class CustomSafeLoader(_SafeLoader): # ty: ignore[unsupported-base]
"""SafeLoader with YAML 1.2 bool handling and timestamp-as-string."""

yaml_constructors = _SafeLoader.yaml_constructors.copy()
Expand Down
2 changes: 1 addition & 1 deletion tests/main/test_main_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def test_run_generate_from_config_generate_kwargs_are_pinned() -> None:
"""Pin the validated CLI Config values overlaid before generate() runs."""
assert _run_generate_from_config_generate_kwargs() == snapshot([
("input_", "input_"),
("config", "generation_config"),
("config", "cast('Any', generation_config)"),
])
assert _run_generate_from_config_model_copy_updates() == snapshot([
("input_filename", "None"),
Expand Down
Loading