Skip to content

Commit 6585d9c

Browse files
RinZ27blink1073
andauthored
PYTHON-2442: Refactor: use _asdict() in _options_dict() (#2670)
Co-authored-by: Steven Silvester <steve.silvester@mongodb.com>
1 parent fdb1f7e commit 6585d9c

File tree

2 files changed

+2
-31
lines changed

2 files changed

+2
-31
lines changed

bson/codec_options.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,6 @@ def with_options(self, **kwargs: Any) -> CodecOptions[Any]:
273273
def _arguments_repr(self) -> str:
274274
...
275275

276-
def _options_dict(self) -> dict[Any, Any]:
277-
...
278-
279276
# NamedTuple API
280277
@classmethod
281278
def _make(cls, obj: Iterable[Any]) -> CodecOptions[_DocumentType]:
@@ -466,19 +463,6 @@ def _arguments_repr(self) -> str:
466463
)
467464
)
468465

469-
def _options_dict(self) -> dict[str, Any]:
470-
"""Dictionary of the arguments used to create this object."""
471-
# TODO: PYTHON-2442 use _asdict() instead
472-
return {
473-
"document_class": self.document_class,
474-
"tz_aware": self.tz_aware,
475-
"uuid_representation": self.uuid_representation,
476-
"unicode_decode_error_handler": self.unicode_decode_error_handler,
477-
"tzinfo": self.tzinfo,
478-
"type_registry": self.type_registry,
479-
"datetime_conversion": self.datetime_conversion,
480-
}
481-
482466
def __repr__(self) -> str:
483467
return f"{self.__class__.__name__}({self._arguments_repr()})"
484468

@@ -494,7 +478,7 @@ def with_options(self, **kwargs: Any) -> CodecOptions:
494478
495479
.. versionadded:: 3.5
496480
"""
497-
opts = self._options_dict()
481+
opts = self._asdict()
498482
opts.update(kwargs)
499483
return CodecOptions(**opts)
500484

bson/json_util.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -382,19 +382,6 @@ def _arguments_repr(self) -> str:
382382
)
383383
)
384384

385-
def _options_dict(self) -> dict[Any, Any]:
386-
# TODO: PYTHON-2442 use _asdict() instead
387-
options_dict = super()._options_dict()
388-
options_dict.update(
389-
{
390-
"strict_number_long": self.strict_number_long,
391-
"datetime_representation": self.datetime_representation,
392-
"strict_uuid": self.strict_uuid,
393-
"json_mode": self.json_mode,
394-
}
395-
)
396-
return options_dict
397-
398385
def with_options(self, **kwargs: Any) -> JSONOptions:
399386
"""
400387
Make a copy of this JSONOptions, overriding some options::
@@ -408,7 +395,7 @@ def with_options(self, **kwargs: Any) -> JSONOptions:
408395
409396
.. versionadded:: 3.12
410397
"""
411-
opts = self._options_dict()
398+
opts = self._asdict()
412399
for opt in ("strict_number_long", "datetime_representation", "strict_uuid", "json_mode"):
413400
opts[opt] = kwargs.get(opt, getattr(self, opt))
414401
opts.update(kwargs)

0 commit comments

Comments
 (0)