@@ -63,12 +63,10 @@ class TypeEncoder(abc.ABC):
63
63
@abc .abstractproperty
64
64
def python_type (self ) -> Any :
65
65
"""The Python type to be converted into something serializable."""
66
- pass
67
66
68
67
@abc .abstractmethod
69
68
def transform_python (self , value : Any ) -> Any :
70
69
"""Convert the given Python object into something serializable."""
71
- pass
72
70
73
71
74
72
class TypeDecoder (abc .ABC ):
@@ -84,12 +82,10 @@ class TypeDecoder(abc.ABC):
84
82
@abc .abstractproperty
85
83
def bson_type (self ) -> Any :
86
84
"""The BSON type to be converted into our own type."""
87
- pass
88
85
89
86
@abc .abstractmethod
90
87
def transform_bson (self , value : Any ) -> Any :
91
88
"""Convert the given BSON value into our own type."""
92
- pass
93
89
94
90
95
91
class TypeCodec (TypeEncoder , TypeDecoder ):
@@ -105,14 +101,12 @@ class TypeCodec(TypeEncoder, TypeDecoder):
105
101
See :ref:`custom-type-type-codec` documentation for an example.
106
102
"""
107
103
108
- pass
109
-
110
104
111
105
_Codec = Union [TypeEncoder , TypeDecoder , TypeCodec ]
112
106
_Fallback = Callable [[Any ], Any ]
113
107
114
108
115
- class TypeRegistry ( object ) :
109
+ class TypeRegistry :
116
110
"""Encapsulates type codecs used in encoding and / or decoding BSON, as
117
111
well as the fallback encoder. Type registries cannot be modified after
118
112
instantiation.
@@ -164,8 +158,7 @@ def __init__(
164
158
self ._decoder_map [codec .bson_type ] = codec .transform_bson
165
159
if not is_valid_codec :
166
160
raise TypeError (
167
- "Expected an instance of %s, %s, or %s, got %r instead"
168
- % (TypeEncoder .__name__ , TypeDecoder .__name__ , TypeCodec .__name__ , codec )
161
+ f"Expected an instance of { TypeEncoder .__name__ } , { TypeDecoder .__name__ } , or { TypeCodec .__name__ } , got { codec !r} instead"
169
162
)
170
163
171
164
def _validate_type_encoder (self , codec : _Codec ) -> None :
@@ -175,12 +168,12 @@ def _validate_type_encoder(self, codec: _Codec) -> None:
175
168
if issubclass (cast (TypeCodec , codec ).python_type , pytype ):
176
169
err_msg = (
177
170
"TypeEncoders cannot change how built-in types are "
178
- "encoded (encoder %s transforms type %s)" % (codec , pytype )
171
+ "encoded (encoder {} transforms type {})" . format (codec , pytype )
179
172
)
180
173
raise TypeError (err_msg )
181
174
182
175
def __repr__ (self ):
183
- return "%s (type_codecs=%r , fallback_encoder=%r)" % (
176
+ return "{} (type_codecs={!r} , fallback_encoder={!r})" . format (
184
177
self .__class__ .__name__ ,
185
178
self .__type_codecs ,
186
179
self ._fallback_encoder ,
@@ -446,10 +439,9 @@ def _arguments_repr(self) -> str:
446
439
)
447
440
448
441
return (
449
- "document_class=%s, tz_aware=%r, uuid_representation=%s, "
450
- "unicode_decode_error_handler=%r, tzinfo=%r, "
451
- "type_registry=%r, datetime_conversion=%s"
452
- % (
442
+ "document_class={}, tz_aware={!r}, uuid_representation={}, "
443
+ "unicode_decode_error_handler={!r}, tzinfo={!r}, "
444
+ "type_registry={!r}, datetime_conversion={!s}" .format (
453
445
document_class_repr ,
454
446
self .tz_aware ,
455
447
uuid_rep_repr ,
@@ -474,7 +466,7 @@ def _options_dict(self) -> Dict[str, Any]:
474
466
}
475
467
476
468
def __repr__ (self ):
477
- return "%s(%s)" % ( self .__class__ .__name__ , self ._arguments_repr ())
469
+ return f" { self .__class__ .__name__ } ( { self ._arguments_repr ()} )"
478
470
479
471
def with_options (self , ** kwargs : Any ) -> "CodecOptions" :
480
472
"""Make a copy of this CodecOptions, overriding some options::
0 commit comments