Skip to content

Commit 5faafb0

Browse files
Fix some typing issues
1 parent 6873d3c commit 5faafb0

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

src/aiida/cmdline/commands/cmd_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def verdi_code():
3838
def create_code(ctx: click.Context, cls: 'Code', **kwargs) -> None:
3939
"""Create a new `Code` instance."""
4040
try:
41-
Model = cls.Model.as_input_model()
41+
Model = cls.Model.as_input_model() # noqa: N806
4242
instance = cls.from_model(Model(**kwargs))
4343
except (TypeError, ValueError) as exception:
4444
echo.echo_critical(f'Failed to create instance `{cls}`: {exception}')

src/aiida/cmdline/groups/dynamic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def call_command(self, ctx: click.Context, cls: t.Any, non_interactive: bool, **
9797

9898
if hasattr(cls, 'Model'):
9999
# The plugin defines a pydantic model: use it to validate the provided arguments
100-
Model = cls.Model.as_input_model() if hasattr(cls.Model, 'as_input_model') else cls.Model
100+
Model = cls.Model.as_input_model() if hasattr(cls.Model, 'as_input_model') else cls.Model # noqa: N806
101101
try:
102102
Model(**kwargs)
103103
except ValidationError as exception:
@@ -169,7 +169,7 @@ def list_options(self, entry_point: str) -> list[t.Callable[[FC], FC]]:
169169
options_spec = self.factory(entry_point).get_cli_options() # type: ignore[union-attr]
170170
return [self.create_option(*item) for item in options_spec]
171171

172-
Model = cls.Model.as_input_model() if hasattr(cls.Model, 'as_input_model') else cls.Model
172+
Model = cls.Model.as_input_model() if hasattr(cls.Model, 'as_input_model') else cls.Model # noqa: N806
173173

174174
options_spec = {}
175175

src/aiida/orm/entities.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import pathlib
1515
from enum import Enum
1616
from functools import lru_cache
17-
from typing import TYPE_CHECKING, Any, Generic, List, Literal, Optional, Type, TypeVar, Union, cast
17+
from typing import TYPE_CHECKING, Any, Generic, List, Literal, Optional, Type, TypeVar, Union
1818

1919
from plumpy.base.utils import call_with_super_check, super_check
2020
from pydantic import BaseModel, ConfigDict, create_model
@@ -95,7 +95,7 @@ def __call__(self, backend: 'StorageBackend') -> Self:
9595
"""Get or create a cached collection using a new backend."""
9696
if backend is self._backend:
9797
return self
98-
return self.get_cached(self.entity_type, backend=backend) # type: ignore[arg-type]
98+
return self.get_cached(self.entity_type, backend=backend)
9999

100100
@property
101101
def entity_type(self) -> Type[EntityType]:
@@ -213,7 +213,7 @@ def as_input_model(cls: Type[EntityModelType]) -> Type[EntityModelType]:
213213

214214
# Derive the input model from the original model
215215
new_name = cls.__qualname__.replace('.Model', 'InputModel')
216-
InputModel = create_model(
216+
InputModel = create_model( # noqa: N806
217217
new_name,
218218
__base__=cls,
219219
__doc__=f'Input version of {cls.__name__}.',
@@ -225,7 +225,7 @@ def as_input_model(cls: Type[EntityModelType]) -> Type[EntityModelType]:
225225
readonly_fields = [
226226
name
227227
for name, field in InputModel.model_fields.items()
228-
if getattr(field, 'json_schema_extra', {}) and field.json_schema_extra.get('readOnly')
228+
if getattr(field, 'json_schema_extra', {}).get('readOnly')
229229
]
230230

231231
# Remove read-only fields
@@ -247,7 +247,7 @@ def _prune_field_decorators(field_decorators: dict[str, Any]) -> dict[str, Any]:
247247
decorators.field_validators = _prune_field_decorators(decorators.field_validators)
248248
decorators.field_serializers = _prune_field_decorators(decorators.field_serializers)
249249

250-
return cast(Type[EntityModelType], InputModel)
250+
return InputModel
251251

252252
@classmethod
253253
def model_to_orm_fields(cls) -> dict[str, FieldInfo]:
@@ -297,7 +297,7 @@ def to_model(self, repository_path: Optional[pathlib.Path] = None, unstored: boo
297297
"""
298298
fields = {}
299299

300-
Model = self.Model.as_input_model() if unstored else self.Model
300+
Model = self.Model.as_input_model() if unstored else self.Model # noqa: N806
301301

302302
for key, field in Model.model_fields.items():
303303
if orm_to_model := get_metadata(field, 'orm_to_model'):
@@ -360,7 +360,7 @@ def from_serialized(cls, unstored: bool = False, **kwargs: dict[str, Any]) -> 'E
360360
cls._logger.warning(
361361
'Serialization through pydantic is still an experimental feature and might break in future releases.'
362362
)
363-
Model = cls.Model.as_input_model() if unstored else cls.Model
363+
Model = cls.Model.as_input_model() if unstored else cls.Model # noqa: N806
364364
return cls.from_model(Model(**kwargs)) # type: ignore[arg-type]
365365

366366
@classproperty

src/aiida/orm/groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Model(entities.Entity.Model):
123123
exclude_to_orm=True,
124124
)
125125
user: int = MetadataField(
126-
default_factory=lambda: users.User.collection.get_default().pk,
126+
default_factory=lambda: users.User.collection.get_default().pk, # type: ignore[union-attr]
127127
description='The PK of the group owner, defaults to the current user',
128128
is_attribute=False,
129129
orm_class='core.user',

src/aiida/orm/nodes/data/array/trajectory.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class Model(ArrayData.Model):
4343
)
4444
symbols: List[str] = MetadataField(description='List of symbols')
4545

46-
4746
def __init__(
4847
self,
4948
structurelist: list[orm.StructureData] | None = None,
@@ -105,7 +104,7 @@ def _internal_validate(self, stepids, cells, symbols, positions, times, velociti
105104
numatoms = len(symbols)
106105
if positions.shape != (numsteps, numatoms, 3):
107106
raise ValueError(
108-
'TrajectoryData.positions must have shape (s,n,3), ' 'with s=number of steps and n=number of symbols'
107+
'TrajectoryData.positions must have shape (s,n,3), with s=number of steps and n=number of symbols'
109108
)
110109
if times is not None:
111110
if times.shape != (numsteps,):
@@ -426,7 +425,7 @@ def get_step_structure(self, index, custom_kinds=None):
426425
for k in custom_kinds:
427426
if not isinstance(k, Kind):
428427
raise TypeError(
429-
'Each element of the custom_kinds list must ' 'be a aiida.orm.nodes.data.structure.Kind object'
428+
'Each element of the custom_kinds list must be a aiida.orm.nodes.data.structure.Kind object'
430429
)
431430
kind_names.append(k.name)
432431
if len(kind_names) != len(set(kind_names)):

0 commit comments

Comments
 (0)