From 176192bfae275091183c65ea10e01197be074a46 Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Tue, 17 Mar 2026 14:51:02 -0400 Subject: [PATCH 1/2] PYTHON-5758 Remove unused validation functions --- doc/changelog.rst | 9 +++++++++ pymongo/common.py | 29 ----------------------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index f38709203c..a48202e19d 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,6 +6,15 @@ Changes in Version 4.17.0 (2026/XX/XX) PyMongo 4.17 brings a number of changes including: +- Remove unused validation functions from pymongo/common.py + + - validate_positive_integer_or_none (line 236) — superseded by + validate_non_negative_integer_or_none which is used + - validate_int_or_basestring (line 264) — a variant of + validate_non_negative_int_or_basestring which is used + - validate_auth_option (line 823) — validates auth mechanism properties but + is never invoked + - Added the :meth:`~pymongo.asynchronous.client_session.AsyncClientSession.bind` and :meth:`~pymongo.client_session.ClientSession.bind` methods that allow users to bind a session to all database operations within the scope of a context manager instead of having to explicitly pass the session to each individual operation. See for examples and more information. diff --git a/pymongo/common.py b/pymongo/common.py index e23adac426..cc53cc65ec 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -233,13 +233,6 @@ def validate_readable(option: str, value: Any) -> Optional[str]: return value -def validate_positive_integer_or_none(option: str, value: Any) -> Optional[int]: - """Validate that 'value' is a positive integer or None.""" - if value is None: - return value - return validate_positive_integer(option, value) - - def validate_non_negative_integer_or_none(option: str, value: Any) -> Optional[int]: """Validate that 'value' is a positive integer or 0 or None.""" if value is None: @@ -261,20 +254,6 @@ def validate_string_or_none(option: str, value: Any) -> Optional[str]: return validate_string(option, value) -def validate_int_or_basestring(option: str, value: Any) -> Union[int, str]: - """Validates that 'value' is an integer or string.""" - if isinstance(value, int): - return value - elif isinstance(value, str): - try: - return int(value) - except ValueError: - return value - raise TypeError( - f"Wrong type for {option}, value must be an integer or a string, not {type(value)}" - ) - - def validate_non_negative_int_or_basestring(option: Any, value: Any) -> Union[int, str]: """Validates that 'value' is an integer or string.""" if isinstance(value, int): @@ -820,14 +799,6 @@ def validate_server_monitoring_mode(option: str, value: str) -> str: _AUTH_OPTIONS = frozenset(["authmechanismproperties"]) -def validate_auth_option(option: str, value: Any) -> tuple[str, Any]: - """Validate optional authentication parameters.""" - lower, value = validate(option, value) - if lower not in _AUTH_OPTIONS: - raise ConfigurationError(f"Unknown option: {option}. Must be in {_AUTH_OPTIONS}") - return option, value - - def _get_validator( key: str, validators: dict[str, Callable[[Any, Any], Any]], normed_key: Optional[str] = None ) -> Callable[[Any, Any], Any]: From 9314d696f9ce2da0d9fa54dcb33acacdf71d9a0b Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Tue, 17 Mar 2026 15:29:11 -0400 Subject: [PATCH 2/2] Address review feedback --- doc/changelog.rst | 9 --------- pymongo/common.py | 2 -- 2 files changed, 11 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index a48202e19d..f38709203c 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,15 +6,6 @@ Changes in Version 4.17.0 (2026/XX/XX) PyMongo 4.17 brings a number of changes including: -- Remove unused validation functions from pymongo/common.py - - - validate_positive_integer_or_none (line 236) — superseded by - validate_non_negative_integer_or_none which is used - - validate_int_or_basestring (line 264) — a variant of - validate_non_negative_int_or_basestring which is used - - validate_auth_option (line 823) — validates auth mechanism properties but - is never invoked - - Added the :meth:`~pymongo.asynchronous.client_session.AsyncClientSession.bind` and :meth:`~pymongo.client_session.ClientSession.bind` methods that allow users to bind a session to all database operations within the scope of a context manager instead of having to explicitly pass the session to each individual operation. See for examples and more information. diff --git a/pymongo/common.py b/pymongo/common.py index cc53cc65ec..118cca89db 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -796,8 +796,6 @@ def validate_server_monitoring_mode(option: str, value: str) -> str: "waitqueuetimeoutms", ] -_AUTH_OPTIONS = frozenset(["authmechanismproperties"]) - def _get_validator( key: str, validators: dict[str, Callable[[Any, Any], Any]], normed_key: Optional[str] = None