43
43
)
44
44
from .grpc .grpclib_client import ServiceStub
45
45
46
+ # Circular import workaround: google.protobuf depends on base classes defined above.
47
+ from .lib .google .protobuf import DoubleValue # noqa
48
+ from .lib .google .protobuf import (
49
+ BoolValue ,
50
+ BytesValue ,
51
+ Duration ,
52
+ EnumValue ,
53
+ FloatValue ,
54
+ Int32Value ,
55
+ Int64Value ,
56
+ StringValue ,
57
+ Timestamp ,
58
+ UInt32Value ,
59
+ UInt64Value ,
60
+ )
61
+
46
62
47
63
# Proto 3 data types
48
64
TYPE_ENUM : Final = "enum"
@@ -454,7 +470,7 @@ def _parse_float(value: Any) -> float:
454
470
if value == INFINITY :
455
471
return float ("inf" )
456
472
if value == NEG_INFINITY :
457
- return - float ("inf" )
473
+ return float ("- inf" )
458
474
if value == NAN :
459
475
return float ("nan" )
460
476
return float (value )
@@ -476,7 +492,7 @@ def _dump_float(value: float) -> Union[float, str]:
476
492
"""
477
493
if value == float ("inf" ):
478
494
return INFINITY
479
- if value == - float ("inf" ):
495
+ if value == float ("- inf" ):
480
496
return NEG_INFINITY
481
497
if value == float ("nan" ):
482
498
return NAN
@@ -1162,9 +1178,7 @@ def to_dict(
1162
1178
elif meta .proto_type == TYPE_ENUM :
1163
1179
if field_is_repeated :
1164
1180
enum_class = field_types [field_name ].__args__ [0 ]
1165
- if isinstance (value , typing .Iterable ) and not isinstance (
1166
- value , str
1167
- ):
1181
+ if hasattr (value , "__iter__" ) and not isinstance (value , str ):
1168
1182
output [cased_name ] = [enum_class (el ).name for el in value ]
1169
1183
else :
1170
1184
# transparently upgrade single value to repeated
@@ -1362,23 +1376,6 @@ def which_one_of(message: Message, group_name: str) -> Tuple[str, Optional[Any]]
1362
1376
return field_name , getattr (message , field_name )
1363
1377
1364
1378
1365
- # Circular import workaround: google.protobuf depends on base classes defined above.
1366
- from .lib .google .protobuf import ( # noqa
1367
- BoolValue ,
1368
- BytesValue ,
1369
<
8FB9
/td>- DoubleValue ,
1370
- Duration ,
1371
- EnumValue ,
1372
- FloatValue ,
1373
- Int32Value ,
1374
- Int64Value ,
1375
- StringValue ,
1376
- Timestamp ,
1377
- UInt32Value ,
1378
- UInt64Value ,
1379
- )
1380
-
1381
-
1382
1379
class _Duration (Duration ):
1383
1380
def to_timedelta (self ) -> timedelta :
1384
1381
return timedelta (seconds = self .seconds , microseconds = self .nanos / 1e3 )
0 commit comments