@@ -63,12 +63,10 @@ class TypeEncoder(abc.ABC):
6363 @abc .abstractproperty
6464 def python_type (self ) -> Any :
6565 """The Python type to be converted into something serializable."""
66- pass
6766
6867 @abc .abstractmethod
6968 def transform_python (self , value : Any ) -> Any :
7069 """Convert the given Python object into something serializable."""
71- pass
7270
7371
7472class TypeDecoder (abc .ABC ):
@@ -84,12 +82,10 @@ class TypeDecoder(abc.ABC):
8482 @abc .abstractproperty
8583 def bson_type (self ) -> Any :
8684 """The BSON type to be converted into our own type."""
87- pass
8885
8986 @abc .abstractmethod
9087 def transform_bson (self , value : Any ) -> Any :
9188 """Convert the given BSON value into our own type."""
92- pass
9389
9490
9591class TypeCodec (TypeEncoder , TypeDecoder ):
@@ -105,14 +101,12 @@ class TypeCodec(TypeEncoder, TypeDecoder):
105101 See :ref:`custom-type-type-codec` documentation for an example.
106102 """
107103
108- pass
109-
110104
111105_Codec = Union [TypeEncoder , TypeDecoder , TypeCodec ]
112106_Fallback = Callable [[Any ], Any ]
113107
114108
115- class TypeRegistry ( object ) :
109+ class TypeRegistry :
116110 """Encapsulates type codecs used in encoding and / or decoding BSON, as
117111 well as the fallback encoder. Type registries cannot be modified after
118112 instantiation.
@@ -164,8 +158,7 @@ def __init__(
164158 self ._decoder_map [codec .bson_type ] = codec .transform_bson
165159 if not is_valid_codec :
166160 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"
169162 )
170163
171164 def _validate_type_encoder (self , codec : _Codec ) -> None :
@@ -175,12 +168,12 @@ def _validate_type_encoder(self, codec: _Codec) -> None:
175168 if issubclass (cast (TypeCodec , codec ).python_type , pytype ):
176169 err_msg = (
177170 "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 )
179172 )
180173 raise TypeError (err_msg )
181174
182175 def __repr__ (self ):
183- return "%s (type_codecs=%r , fallback_encoder=%r)" % (
176+ return "{} (type_codecs={!r} , fallback_encoder={!r})" . format (
184177 self .__class__ .__name__ ,
185178 self .__type_codecs ,
186179 self ._fallback_encoder ,
@@ -446,10 +439,9 @@ def _arguments_repr(self) -> str:
446439 )
447440
448441 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 (
453445 document_class_repr ,
454446 self .tz_aware ,
455447 uuid_rep_repr ,
@@ -474,7 +466,7 @@ def _options_dict(self) -> Dict[str, Any]:
474466 }
475467
476468 def __repr__ (self ):
477- return "%s(%s)" % ( self .__class__ .__name__ , self ._arguments_repr ())
469+ return f" { self .__class__ .__name__ } ( { self ._arguments_repr ()} )"
478470
479471 def with_options (self , ** kwargs : Any ) -> "CodecOptions" :
480472 """Make a copy of this CodecOptions, overriding some options::
0 commit comments