diff --git a/gridfs/grid_file.py b/gridfs/grid_file.py index 971170c6c..ac72c144b 100644 --- a/gridfs/grid_file.py +++ b/gridfs/grid_file.py @@ -19,6 +19,7 @@ import datetime import io import math import os +import warnings from typing import Any, Iterable, Mapping, NoReturn, Optional from bson.int64 import Int64 @@ -69,8 +70,15 @@ def _grid_in_property( closed_only: Optional[bool] = False, ) -> Any: """Create a GridIn property.""" + warn_str = "" + if docstring.startswith("DEPRECATED,"): + warn_str = ( + f"GridIn property '{field_name}' is deprecated and will be removed in PyMongo 5.0" + ) def getter(self: Any) -> Any: + if warn_str: + warnings.warn(warn_str, stacklevel=2, category=DeprecationWarning) if closed_only and not self._closed: raise AttributeError("can only get %r on a closed file" % field_name) # Protect against PHP-237 @@ -79,6 +87,8 @@ def _grid_in_property( return self._file.get(field_name, None) def setter(self: Any, value: Any) -> Any: + if warn_str: + warnings.warn(warn_str, stacklevel=2, category=DeprecationWarning) if self._closed: self._coll.files.update_one({"_id": self._file["_id"]}, {"$set": {field_name: value}}) self._file[field_name] = value @@ -100,8 +110,15 @@ def _grid_in_property( def _grid_out_property(field_name: str, docstring: str) -> Any: """Create a GridOut property.""" + warn_str = "" + if docstring.startswith("DEPRECATED,"): + warn_str = ( + f"GridOut property '{field_name}' is deprecated and will be removed in PyMongo 5.0" + ) def getter(self: Any) -> Any: + if warn_str: + warnings.warn(warn_str, stacklevel=2, category=DeprecationWarning) self._ensure_file() # Protect against PHP-237 diff --git a/pyproject.toml b/pyproject.toml index 3cdb03a1b..40c564689 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -115,6 +115,8 @@ filterwarnings = [ "module:Unsupported compressor:UserWarning", "module:zlibcompressionlevel must be:UserWarning", "module:Wire protocol compression with:UserWarning", + "module:GridIn property:DeprecationWarning", + "module:GridOut property:DeprecationWarning", # TODO: Remove as part of PYTHON-3923. "module:unclosed