19
19
import io
20
20
import math
21
21
import os
22
+ import warnings
22
23
from typing import Any , Iterable , Mapping , NoReturn , Optional
23
24
24
25
from bson .int64 import Int64
@@ -69,8 +70,15 @@ def _grid_in_property(
69
70
closed_only : Optional [bool ] = False ,
70
71
) -> Any :
71
72
"""Create a GridIn property."""
73
+ warn_str = ""
74
+ if docstring .startswith ("DEPRECATED," ):
75
+ warn_str = (
76
+ f"GridIn property '{ field_name } ' is deprecated and will be removed in PyMongo 5.0"
77
+ )
72
78
73
79
def getter (self : Any ) -> Any :
80
+ if warn_str :
81
+ warnings .warn (warn_str , stacklevel = 2 , category = DeprecationWarning )
74
82
if closed_only and not self ._closed :
75
83
raise AttributeError ("can only get %r on a closed file" % field_name )
76
84
# Protect against PHP-237
@@ -79,6 +87,8 @@ def getter(self: Any) -> Any:
79
87
return self ._file .get (field_name , None )
80
88
81
89
def setter (self : Any , value : Any ) -> Any :
90
+ if warn_str :
91
+ warnings .warn (warn_str , stacklevel = 2 , category = DeprecationWarning )
82
92
if self ._closed :
83
93
self ._coll .files .update_one ({"_id" : self ._file ["_id" ]}, {"$set" : {field_name : value }})
84
94
self ._file [field_name ] = value
@@ -100,8 +110,15 @@ def setter(self: Any, value: Any) -> Any:
100
110
101
111
def _grid_out_property (field_name : str , docstring : str ) -> Any :
102
112
"""Create a GridOut property."""
113
+ warn_str = ""
114
+ if docstring .startswith ("DEPRECATED," ):
115
+ warn_str = (
116
+ f"GridOut property '{ field_name } ' is deprecated and will be removed in PyMongo 5.0"
117
+ )
103
118
104
119
def getter (self : Any ) -> Any :
120
+ if warn_str :
121
+ warnings .warn (warn_str , stacklevel = 2 , category = DeprecationWarning )
105
122
self ._ensure_file ()
106
123
107
124
# Protect against PHP-237
0 commit comments