@@ -678,7 +678,7 @@ def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
678678 return self
679679
680680
681- class EnumMeta (SchemaMeta ):
681+ class EnumMeta (SchemaMeta , Generic [ ET ] ):
682682 """Meta class to add dynamic support for :class:`EnumSchema`.
683683
684684 This meta class is used to generate necessary attributes for the
@@ -687,7 +687,7 @@ class EnumMeta(SchemaMeta):
687687
688688 * :attr:`~EnumSchema.registry` is added to subclasses as an *immutable*
689689 proxy (similar to :class:`property`, but on class variables) to the
690- :attr:`~EnumSchema. __enum__` mapping.
690+ :attr:`__enum__` mapping.
691691
692692 Args:
693693 name: Schema class name.
@@ -697,10 +697,14 @@ class EnumMeta(SchemaMeta):
697697
698698 """
699699
700+ if TYPE_CHECKING :
701+ #: Mapping of enumeration numbers to schemas (**internal use only**).
702+ __enum__ : 'DefaultDict[ET, Type[EnumSchema]]'
703+
700704 @property
701705 def registry (cls ) -> 'DefaultDict[ET, Type[EnumSchema]]' :
702706 """Mapping of enumeration numbers to schemas."""
703- return cls .__enum__ # type: ignore[attr-defined]
707+ return cls .__enum__
704708
705709
706710class EnumSchema (Schema , Generic [ET ], metaclass = EnumMeta ):
@@ -753,10 +757,9 @@ class MultipleSchema(MySchema, code=[MyEnum.TWO, MyEnum.THREE]):
753757 __default__ : 'Callable[[], Type[Self]]' = lambda : None # type: ignore[assignment,return-value]
754758
755759 if TYPE_CHECKING :
756- #: Mapping of enumeration numbers to schemas (**internal use only**).
757- __enum__ : 'DefaultDict[ET, Type[Self]]'
758760 #: Mapping of enumeration numbers to schemas.
759761 registry : 'DefaultDict[ET, Type[Self]]'
762+ __enum__ : 'DefaultDict[ET, Type[Self]]'
760763
761764 def __init_subclass__ (cls , / , code : 'Optional[ET | Iterable[ET]]' = None , * args : 'Any' , ** kwargs : 'Any' ) -> 'None' :
762765 """Register enumeration to :attr:`registry` mapping.
@@ -772,13 +775,13 @@ def __init_subclass__(cls, /, code: 'Optional[ET | Iterable[ET]]' = None, *args:
772775 not given, the subclass will not be registered.
773776
774777 Notes:
775- If :attr:`__enum__` is not yet defined at function call, it will
776- automatically be defined as a :class:`collections.defaultdict`
778+ If :attr:`~EnumMeta. __enum__` is not yet defined at function call,
779+ it will automatically be defined as a :class:`collections.defaultdict`
777780 object, with the default value set to :attr:`__default__`.
778781
779- If intended to customise the :attr:`__enum__` mapping, it is
780- possible to override the :meth:`__init_subclass__` method and
781- define :attr:`__enum__` manually.
782+ If intended to customise the :attr:`~EnumMeta. __enum__` mapping,
783+ it is possible to override the :meth:`__init_subclass__` method and
784+ define :attr:`~EnumMeta. __enum__` manually.
782785
783786 """
784787 if not hasattr (cls , '__enum__' ):
@@ -787,9 +790,9 @@ def __init_subclass__(cls, /, code: 'Optional[ET | Iterable[ET]]' = None, *args:
787790 if code is not None :
788791 if isinstance (code , collections .abc .Iterable ):
789792 for _code in code :
790- cls .__enum__ [_code ] = cls
793+ cls .__enum__ [_code ] = ( cls )
791794 else :
792- cls .__enum__ [code ] = cls
795+ cls .__enum__ [code ] = ( cls )
793796 super ().__init_subclass__ ()
794797
795798 @classmethod
0 commit comments