@@ -220,7 +220,7 @@ def _dict_without_impl(self):
220220 return self .__dict__
221221
222222 def to_type_hint (self ):
223- raise NotImplementedError ('BEAM-2717' )
223+ raise NotImplementedError ('BEAM-2717: %s' % self . __class__ . __name__ )
224224
225225 @classmethod
226226 def from_type_hint (cls , unused_typehint , unused_registry ):
@@ -532,6 +532,9 @@ def __eq__(self, other):
532532 def __hash__ (self ):
533533 return hash (type (self )) + hash (self ._key_coder ) + hash (self ._value_coder )
534534
535+ def __repr__ (self ):
536+ return 'MapCoder[%s, %s]' % (self ._key_coder , self ._value_coder )
537+
535538
536539class NullableCoder (FastCoder ):
537540 def __init__ (self , value_coder ):
@@ -929,10 +932,10 @@ def __eq__(self, other):
929932 def __hash__ (self ):
930933 return hash (self .proto_message_type )
931934
932- @staticmethod
933- def from_type_hint (typehint , unused_registry ):
935+ @classmethod
936+ def from_type_hint (cls , typehint , unused_registry ):
934937 if issubclass (typehint , proto_utils .message_types ):
935- return ProtoCoder (typehint )
938+ return cls (typehint )
936939 else :
937940 raise ValueError ((
938941 'Expected a subclass of google.protobuf.message.Message'
@@ -1019,10 +1022,10 @@ def as_deterministic_coder(self, step_label, error_message=None):
10191022 def to_type_hint (self ):
10201023 return typehints .Tuple [tuple (c .to_type_hint () for c in self ._coders )]
10211024
1022- @staticmethod
1023- def from_type_hint (typehint , registry ):
1025+ @classmethod
1026+ def from_type_hint (cls , typehint , registry ):
10241027 # type: (typehints.TupleConstraint, CoderRegistry) -> TupleCoder
1025- return TupleCoder ([registry .get_coder (t ) for t in typehint .tuple_types ])
1028+ return cls ([registry .get_coder (t ) for t in typehint .tuple_types ])
10261029
10271030 def as_cloud_object (self , coders_context = None ):
10281031 if self .is_kv_coder ():
@@ -1106,10 +1109,10 @@ def as_deterministic_coder(self, step_label, error_message=None):
11061109 return TupleSequenceCoder (
11071110 self ._elem_coder .as_deterministic_coder (step_label , error_message ))
11081111
1109- @staticmethod
1110- def from_type_hint (typehint , registry ):
1112+ @classmethod
1113+ def from_type_hint (cls , typehint , registry ):
11111114 # type: (Any, CoderRegistry) -> TupleSequenceCoder
1112- return TupleSequenceCoder (registry .get_coder (typehint .inner_type ))
1115+ return cls (registry .get_coder (typehint .inner_type ))
11131116
11141117 def _get_component_coders (self ):
11151118 # type: () -> Tuple[Coder, ...]
@@ -1484,11 +1487,11 @@ def to_type_hint(self):
14841487 return sharded_key_type .ShardedKeyTypeConstraint (
14851488 self ._key_coder .to_type_hint ())
14861489
1487- @staticmethod
1488- def from_type_hint (typehint , registry ):
1490+ @classmethod
1491+ def from_type_hint (cls , typehint , registry ):
14891492 from apache_beam .typehints import sharded_key_type
14901493 if isinstance (typehint , sharded_key_type .ShardedKeyTypeConstraint ):
1491- return ShardedKeyCoder (registry .get_coder (typehint .key_type ))
1494+ return cls (registry .get_coder (typehint .key_type ))
14921495 else :
14931496 raise ValueError ((
14941497 'Expected an instance of ShardedKeyTypeConstraint'
0 commit comments