ominfra 0.0.0.dev134__py3-none-any.whl → 0.0.0.dev136__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -734,6 +734,13 @@ class PolymorphicObjMarshaler(ObjMarshaler):
734
734
  impls_by_ty: ta.Mapping[type, Impl]
735
735
  impls_by_tag: ta.Mapping[str, Impl]
736
736
 
737
+ @classmethod
738
+ def of(cls, impls: ta.Iterable[Impl]) -> 'PolymorphicObjMarshaler':
739
+ return cls(
740
+ {i.ty: i for i in impls},
741
+ {i.tag: i for i in impls},
742
+ )
743
+
737
744
  def marshal(self, o: ta.Any) -> ta.Any:
738
745
  impl = self.impls_by_ty[type(o)]
739
746
  return {impl.tag: impl.m.marshal(o)}
@@ -821,7 +828,7 @@ def _make_obj_marshaler(
821
828
  ) -> ObjMarshaler:
822
829
  if isinstance(ty, type):
823
830
  if abc.ABC in ty.__bases__:
824
- impls = [ # type: ignore
831
+ return PolymorphicObjMarshaler.of([ # type: ignore
825
832
  PolymorphicObjMarshaler.Impl(
826
833
  ity,
827
834
  ity.__qualname__,
@@ -829,11 +836,7 @@ def _make_obj_marshaler(
829
836
  )
830
837
  for ity in deep_subclasses(ty)
831
838
  if abc.ABC not in ity.__bases__
832
- ]
833
- return PolymorphicObjMarshaler(
834
- {i.ty: i for i in impls},
835
- {i.tag: i for i in impls},
836
- )
839
+ ])
837
840
 
838
841
  if issubclass(ty, enum.Enum):
839
842
  return EnumObjMarshaler(ty)
@@ -0,0 +1 @@
1
+ # @omlish-lite