Skip to content

Commit 87e8e34

Browse files
committed
sat: disable deprecated warnings in cp_model.py
User can reenable them using: ```py from ortools.sat.python import cp_model cp_model.enable_warnings = True ```
1 parent 204b31a commit 87e8e34

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

ortools/sat/python/cp_model.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184

185185

186186
# Helper functions.
187-
187+
enable_warnings = False
188188

189189
# warnings.deprecated is python3.13+. Not compatible with Open Source (3.10+).
190190
# pylint: disable=g-bare-generic
@@ -193,12 +193,13 @@ def deprecated(message: str) -> Callable[[Callable], Callable]:
193193

194194
def deprecated_decorator(func) -> Callable:
195195
def deprecated_func(*args, **kwargs):
196-
warnings.warn(
197-
f"{func.__name__} is a deprecated function. {message}",
198-
category=DeprecationWarning,
199-
stacklevel=2,
200-
)
201-
warnings.simplefilter("default", DeprecationWarning)
196+
if enable_warnings:
197+
warnings.warn(
198+
f"{func.__name__} is a deprecated function. {message}",
199+
category=DeprecationWarning,
200+
stacklevel=2,
201+
)
202+
warnings.simplefilter("default", DeprecationWarning)
202203
return func(*args, **kwargs)
203204

204205
return deprecated_func
@@ -210,12 +211,13 @@ def deprecated_method(func, old_name: str) -> Callable:
210211
"""Wrapper that warns about a deprecated method."""
211212

212213
def deprecated_func(*args, **kwargs) -> Any:
213-
warnings.warn(
214-
f"{old_name} is a deprecated function. Use {func.__name__} instead.",
215-
category=DeprecationWarning,
216-
stacklevel=2,
217-
)
218-
warnings.simplefilter("default", DeprecationWarning)
214+
if enable_warnings:
215+
warnings.warn(
216+
f"{old_name} is a deprecated function. Use {func.__name__} instead.",
217+
category=DeprecationWarning,
218+
stacklevel=2,
219+
)
220+
warnings.simplefilter("default", DeprecationWarning)
219221
return func(*args, **kwargs)
220222

221223
return deprecated_func

0 commit comments

Comments
 (0)