Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FutureWarning instead of DeprecationWarning #1188

Merged
merged 3 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
to print useful debug messages on stderr (useful in case of nasty errors).
- 1177_: added support for sensors_battery() on OSX. (patch by Arnon Yaari)
- 1183_: Process.children() is 2x faster on UNIX and 2.4x faster on Linux.
- 1188_: deprecated method Process.memory_info_ex() now warns by using
FutureWarning instead of DeprecationWarning.

**Bug fixes**

Expand Down
4 changes: 2 additions & 2 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,14 @@ def deprecated_method(replacement):
'replcement' is the method name which will be called instead.
"""
def outer(fun):
msg = "%s() is deprecated; use %s() instead" % (
msg = "%s() is deprecated and will be removed; use %s() instead" % (
fun.__name__, replacement)
if fun.__doc__ is None:
fun.__doc__ = msg

@functools.wraps(fun)
def inner(self, *args, **kwargs):
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
warnings.warn(msg, category=FutureWarning, stacklevel=2)
return getattr(self, replacement)(*args, **kwargs)
return inner
return outer
Expand Down
17 changes: 17 additions & 0 deletions psutil/tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import stat
import time
import traceback
import warnings
from contextlib import closing

from psutil import AIX
Expand Down Expand Up @@ -167,6 +168,22 @@ def test_proc_memory_maps(self):
self.assertEqual(hasit, False if OPENBSD or NETBSD or AIX else True)


# ===================================================================
# --- Test deprecations
# ===================================================================


class TestDeprecations(unittest.TestCase):

def test_memory_info_ex(self):
with warnings.catch_warnings(record=True) as ws:
psutil.Process().memory_info_ex()
w = ws[0]
self.assertIsInstance(w.category(), FutureWarning)
self.assertIn("memory_info_ex() is deprecated", str(w.message))
self.assertIn("use memory_info() instead", str(w.message))


# ===================================================================
# --- System API types
# ===================================================================
Expand Down