Currently, in order to use serializer classes imported from flagsmith-common in strictly typed codebases, we have to use type: ignore or cast created/updated instances to target model types.
We should look into the following:
- Add a
TypeVar to SerializerWithMetadata so subclasses can be annotated as e.g. class FeatureSerializerWithMetadata(SerializerWithMetadata[Feature], CreateFeatureSerializer in the consuming code.
- In
common.types module, try to import the Core API models under if TYPE_CHECKING, and only use type aliases to model.Model if they are not available.
Currently, in order to use serializer classes imported from
flagsmith-commonin strictly typed codebases, we have to usetype: ignoreorcastcreated/updated instances to target model types.We should look into the following:
TypeVartoSerializerWithMetadataso subclasses can be annotated as e.g.class FeatureSerializerWithMetadata(SerializerWithMetadata[Feature], CreateFeatureSerializerin the consuming code.common.typesmodule, try to import the Core API models underif TYPE_CHECKING, and only use type aliases tomodel.Modelif they are not available.