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):
295
295
self .unicode_decode_error_handler , self .tzinfo ,
296
296
self .type_registry ))
297
297
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
+
298
309
def __repr__ (self ):
299
310
return '%s(%s)' % (self .__class__ .__name__ , self ._arguments_repr ())
300
311
@@ -310,7 +321,7 @@ def with_options(self, **kwargs):
310
321
311
322
.. versionadded:: 3.5
312
323
"""
313
- opts = self ._asdict ()
324
+ opts = self ._options_dict ()
314
325
opts .update (kwargs )
315
326
return CodecOptions (** opts )
316
327
Original file line number Diff line number Diff line change @@ -311,6 +311,16 @@ def _arguments_repr(self):
311
311
self .json_mode ,
312
312
super (JSONOptions , self )._arguments_repr ()))
313
313
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
+
314
324
def with_options (self , ** kwargs ):
315
325
"""
316
326
Make a copy of this JSONOptions, overriding some options::
@@ -324,7 +334,7 @@ def with_options(self, **kwargs):
324
334
325
335
.. versionadded:: 3.12
326
336
"""
327
- opts = self ._asdict ()
337
+ opts = self ._options_dict ()
328
338
for opt in ('strict_number_long' , 'datetime_representation' ,
329
339
'strict_uuid' , 'json_mode' ):
330
340
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):
280
280
readpreference = ReadPreference .NEAREST .mongos_mode )
281
281
self .assertEqual (c .read_preference , ReadPreference .NEAREST )
282
282
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" )
283
286
def test_metadata (self ):
284
287
metadata = copy .deepcopy (_METADATA )
285
288
metadata ['application' ] = {'name' : 'foobar' }
You can’t perform that action at this time.
0 commit comments