Skip to content

Commit 176192b

Browse files
committed
PYTHON-5758 Remove unused validation functions
1 parent 80c3ff2 commit 176192b

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

doc/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ Changes in Version 4.17.0 (2026/XX/XX)
66

77
PyMongo 4.17 brings a number of changes including:
88

9+
- Remove unused validation functions from pymongo/common.py
10+
11+
- validate_positive_integer_or_none (line 236) — superseded by
12+
validate_non_negative_integer_or_none which is used
13+
- validate_int_or_basestring (line 264) — a variant of
14+
validate_non_negative_int_or_basestring which is used
15+
- validate_auth_option (line 823) — validates auth mechanism properties but
16+
is never invoked
17+
918
- Added the :meth:`~pymongo.asynchronous.client_session.AsyncClientSession.bind` and :meth:`~pymongo.client_session.ClientSession.bind` methods
1019
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.
1120
See <PLACEHOLDER> for examples and more information.

pymongo/common.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,6 @@ def validate_readable(option: str, value: Any) -> Optional[str]:
233233
return value
234234

235235

236-
def validate_positive_integer_or_none(option: str, value: Any) -> Optional[int]:
237-
"""Validate that 'value' is a positive integer or None."""
238-
if value is None:
239-
return value
240-
return validate_positive_integer(option, value)
241-
242-
243236
def validate_non_negative_integer_or_none(option: str, value: Any) -> Optional[int]:
244237
"""Validate that 'value' is a positive integer or 0 or None."""
245238
if value is None:
@@ -261,20 +254,6 @@ def validate_string_or_none(option: str, value: Any) -> Optional[str]:
261254
return validate_string(option, value)
262255

263256

264-
def validate_int_or_basestring(option: str, value: Any) -> Union[int, str]:
265-
"""Validates that 'value' is an integer or string."""
266-
if isinstance(value, int):
267-
return value
268-
elif isinstance(value, str):
269-
try:
270-
return int(value)
271-
except ValueError:
272-
return value
273-
raise TypeError(
274-
f"Wrong type for {option}, value must be an integer or a string, not {type(value)}"
275-
)
276-
277-
278257
def validate_non_negative_int_or_basestring(option: Any, value: Any) -> Union[int, str]:
279258
"""Validates that 'value' is an integer or string."""
280259
if isinstance(value, int):
@@ -820,14 +799,6 @@ def validate_server_monitoring_mode(option: str, value: str) -> str:
820799
_AUTH_OPTIONS = frozenset(["authmechanismproperties"])
821800

822801

823-
def validate_auth_option(option: str, value: Any) -> tuple[str, Any]:
824-
"""Validate optional authentication parameters."""
825-
lower, value = validate(option, value)
826-
if lower not in _AUTH_OPTIONS:
827-
raise ConfigurationError(f"Unknown option: {option}. Must be in {_AUTH_OPTIONS}")
828-
return option, value
829-
830-
831802
def _get_validator(
832803
key: str, validators: dict[str, Callable[[Any, Any], Any]], normed_key: Optional[str] = None
833804
) -> Callable[[Any, Any], Any]:

0 commit comments

Comments
 (0)