1919object as a creator override.
2020"""
2121
22- from typing import TYPE_CHECKING , Generic , Protocol , TypeVar , runtime_checkable
22+ from typing import TYPE_CHECKING , Generic , Protocol , TypeGuard , TypeVar
2323
2424import attrs
2525
3838T = TypeVar ("T" )
3939
4040
41- @runtime_checkable
4241class AdjustableMeta (Protocol [T ]):
4342 """
4443 An interface used to modify the meta object when creating a field.
@@ -55,7 +54,10 @@ class AdjustableMeta(Protocol[T]):
5554 def adjusted_meta (self , meta : Meta , typ : Type [T ], type_cache : TypeCache ) -> Meta : ...
5655
5756
58- @runtime_checkable
57+ def is_adjustable_meta (meta : object ) -> TypeGuard [AdjustableMeta ]:
58+ return hasattr (meta , "adjusted_meta" )
59+
60+
5961class AdjustableCreator (Protocol [T ]):
6062 """
6163 An interface used to modify the creator used when creating a field.
@@ -88,6 +90,10 @@ def adjusted_creator(
8890 ) -> ConvertFunction [T ] | None : ...
8991
9092
93+ def is_adjustable_creator (meta : object ) -> TypeGuard [AdjustableCreator ]:
94+ return hasattr (meta , "adjusted_creator" )
95+
96+
9197@attrs .define
9298class MetaAnnotation :
9399 """
@@ -226,7 +232,7 @@ def adjusted_meta(self, meta: Meta, typ: Type[T], type_cache: TypeCache) -> Meta
226232 if self .meta is None :
227233 return meta
228234
229- if isinstance (self .meta , AdjustableMeta ):
235+ if is_adjustable_meta (self .meta ):
230236 return self .meta .adjusted_meta (meta , typ , type_cache )
231237
232238 if attrs .has (self .meta .__class__ ):
0 commit comments