@@ -20,7 +20,7 @@ class Converter(Generic[_TPythonType, _TProtobufType], ABC):
2020
2121 @property
2222 @abstractmethod
23- def python_type (self ) -> Type [ _TPythonType ] :
23+ def python_typename (self ) -> str :
2424 """The Python type that this converter handles."""
2525
2626 @property
@@ -61,9 +61,9 @@ class BoolConverter(Converter[bool, wrappers_pb2.BoolValue]):
6161 """A converter for boolean types."""
6262
6363 @property
64- def python_type (self ) -> Type [ bool ] :
64+ def python_typename (self ) -> str :
6565 """The Python type that this converter handles."""
66- return bool
66+ return bool . __name__
6767
6868 @property
6969 def protobuf_message (self ) -> Type [wrappers_pb2 .BoolValue ]:
@@ -83,9 +83,9 @@ class BytesConverter(Converter[bytes, wrappers_pb2.BytesValue]):
8383 """A converter for byte string types."""
8484
8585 @property
86- def python_type (self ) -> Type [ bytes ] :
86+ def python_typename (self ) -> str :
8787 """The Python type that this converter handles."""
88- return bytes
88+ return bytes . __name__
8989
9090 @property
9191 def protobuf_message (self ) -> Type [wrappers_pb2 .BytesValue ]:
@@ -105,9 +105,9 @@ class FloatConverter(Converter[float, wrappers_pb2.DoubleValue]):
105105 """A converter for floating point types."""
106106
107107 @property
108- def python_type (self ) -> Type [ float ] :
108+ def python_typename (self ) -> str :
109109 """The Python type that this converter handles."""
110- return float
110+ return float . __name__
111111
112112 @property
113113 def protobuf_message (self ) -> Type [wrappers_pb2 .DoubleValue ]:
@@ -127,9 +127,9 @@ class IntConverter(Converter[int, wrappers_pb2.Int64Value]):
127127 """A converter for integer types."""
128128
129129 @property
130- def python_type (self ) -> Type [ int ] :
130+ def python_typename (self ) -> str :
131131 """The Python type that this converter handles."""
132- return int
132+ return int . __name__
133133
134134 @property
135135 def protobuf_message (self ) -> Type [wrappers_pb2 .Int64Value ]:
@@ -149,9 +149,9 @@ class StrConverter(Converter[str, wrappers_pb2.StringValue]):
149149 """A converter for text string types."""
150150
151151 @property
152- def python_type (self ) -> Type [ str ] :
152+ def python_typename (self ) -> str :
153153 """The Python type that this converter handles."""
154- return str
154+ return str . __name__
155155
156156 @property
157157 def protobuf_message (self ) -> Type [wrappers_pb2 .StringValue ]:
@@ -176,7 +176,7 @@ def to_python_value(self, protobuf_value: wrappers_pb2.StringValue) -> str:
176176 StrConverter (),
177177]
178178
179- _CONVERTER_FOR_PYTHON_TYPE = {entry .python_type : entry for entry in _CONVERTIBLE_TYPES }
179+ _CONVERTER_FOR_PYTHON_TYPE = {entry .python_typename : entry for entry in _CONVERTIBLE_TYPES }
180180_CONVERTER_FOR_GRPC_TYPE = {entry .protobuf_typename : entry for entry in _CONVERTIBLE_TYPES }
181181_SUPPORTED_PYTHON_TYPES = _CONVERTER_FOR_PYTHON_TYPE .keys ()
182182
@@ -186,7 +186,7 @@ def to_any(python_value: object) -> any_pb2.Any:
186186 underlying_parents = type (python_value ).mro () # This covers enum.IntEnum and similar
187187
188188 best_matching_type = next (
189- (parent for parent in underlying_parents if parent in _SUPPORTED_PYTHON_TYPES ), None
189+ (parent . __name__ for parent in underlying_parents if parent . __name__ in _SUPPORTED_PYTHON_TYPES ), None
190190 )
191191 if not best_matching_type :
192192 raise TypeError (
0 commit comments