File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,17 @@ def _arguments_repr(self):
295295 self .unicode_decode_error_handler , self .tzinfo ,
296296 self .type_registry ))
297297
298+ def _options_dict (self ):
299+ """Dictionary of the arguments used to create this object."""
300+ # TODO: PYTHON-2442 use _asdict() instead
301+ return {
302+ 'document_class' : self .document_class ,
303+ 'tz_aware' : self .tz_aware ,
304+ 'uuid_representation' : self .uuid_representation ,
305+ 'unicode_decode_error_handler' : self .unicode_decode_error_handler ,
306+ 'tzinfo' : self .tzinfo ,
307+ 'type_registry' : self .type_registry }
308+
298309 def __repr__ (self ):
299310 return '%s(%s)' % (self .__class__ .__name__ , self ._arguments_repr ())
300311
@@ -310,7 +321,7 @@ def with_options(self, **kwargs):
310321
311322 .. versionadded:: 3.5
312323 """
313- opts = self ._asdict ()
324+ opts = self ._options_dict ()
314325 opts .update (kwargs )
315326 return CodecOptions (** opts )
316327
Original file line number Diff line number Diff line change @@ -311,6 +311,16 @@ def _arguments_repr(self):
311311 self .json_mode ,
312312 super (JSONOptions , self )._arguments_repr ()))
313313
314+ def _options_dict (self ):
315+ # TODO: PYTHON-2442 use _asdict() instead
316+ options_dict = super (JSONOptions , self )._options_dict ()
317+ options_dict .update ({
318+ 'strict_number_long' : self .strict_number_long ,
319+ 'datetime_representation' : self .datetime_representation ,
320+ 'strict_uuid' : self .strict_uuid ,
321+ 'json_mode' : self .json_mode })
322+ return options_dict
323+
314324 def with_options (self , ** kwargs ):
315325 """
316326 Make a copy of this JSONOptions, overriding some options::
@@ -324,7 +334,7 @@ def with_options(self, **kwargs):
324334
325335 .. versionadded:: 3.12
326336 """
327- opts = self ._asdict ()
337+ opts = self ._options_dict ()
328338 for opt in ('strict_number_long' , 'datetime_representation' ,
329339 'strict_uuid' , 'json_mode' ):
330340 opts [opt ] = kwargs .get (opt , getattr (self , opt ))
Original file line number Diff line number Diff line change @@ -280,6 +280,9 @@ def test_read_preference(self):
280280 readpreference = ReadPreference .NEAREST .mongos_mode )
281281 self .assertEqual (c .read_preference , ReadPreference .NEAREST )
282282
283+ @unittest .skipIf (
284+ sys .version_info [0 ] == 3 and sys .version_info [1 ] == 4 ,
285+ "PYTHON-2442: workaround namedtuple._asdict() bug on Python 3.4" )
283286 def test_metadata (self ):
284287 metadata = copy .deepcopy (_METADATA )
285288 metadata ['application' ] = {'name' : 'foobar' }
You can’t perform that action at this time.
0 commit comments