1414import pathlib
1515from enum import Enum
1616from 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
1919from plumpy .base .utils import call_with_super_check , super_check
2020from 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,9 @@ 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 hasattr (field , 'json_schema_extra' )
229+ and isinstance (field .json_schema_extra , dict )
230+ and field .json_schema_extra .get ('readOnly' )
229231 ]
230232
231233 # Remove read-only fields
@@ -247,7 +249,7 @@ def _prune_field_decorators(field_decorators: dict[str, Any]) -> dict[str, Any]:
247249 decorators .field_validators = _prune_field_decorators (decorators .field_validators )
248250 decorators .field_serializers = _prune_field_decorators (decorators .field_serializers )
249251
250- return cast ( Type [ EntityModelType ], InputModel )
252+ return InputModel
251253
252254 @classmethod
253255 def model_to_orm_fields (cls ) -> dict [str , FieldInfo ]:
@@ -297,7 +299,7 @@ def to_model(self, repository_path: Optional[pathlib.Path] = None, unstored: boo
297299 """
298300 fields = {}
299301
300- Model = self .Model .as_input_model () if unstored else self .Model
302+ Model = self .Model .as_input_model () if unstored else self .Model # noqa: N806
301303
302304 for key , field in Model .model_fields .items ():
303305 if orm_to_model := get_metadata (field , 'orm_to_model' ):
@@ -360,7 +362,7 @@ def from_serialized(cls, unstored: bool = False, **kwargs: dict[str, Any]) -> 'E
360362 cls ._logger .warning (
361363 'Serialization through pydantic is still an experimental feature and might break in future releases.'
362364 )
363- Model = cls .Model .as_input_model () if unstored else cls .Model
365+ Model = cls .Model .as_input_model () if unstored else cls .Model # noqa: N806
364366 return cls .from_model (Model (** kwargs )) # type: ignore[arg-type]
365367
366368 @classproperty
0 commit comments