Skip to content

Commit 596155c

Browse files
committed
Adjust for variable stacklevel on partial calls in PyPy. Fixes #327.
1 parent b49cdaa commit 596155c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v4.6.1
2+
======
3+
4+
* #327: Deprecation warnings now honor call stack variance
5+
on PyPy.
6+
17
v4.6.0
28
======
39

importlib_metadata/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import email
88
import pathlib
99
import operator
10+
import platform
1011
import textwrap
1112
import warnings
1213
import functools
@@ -48,6 +49,16 @@
4849
]
4950

5051

52+
def _pypy_partial(val):
53+
"""
54+
Adjust for variable stacklevel on partial under PyPy.
55+
56+
Workaround for #327.
57+
"""
58+
is_pypy = platform.python_implementation() == 'PyPy'
59+
return val + is_pypy
60+
61+
5162
class PackageNotFoundError(ModuleNotFoundError):
5263
"""The package was not found."""
5364

@@ -245,7 +256,7 @@ class DeprecatedList(list):
245256
warnings.warn,
246257
"EntryPoints list interface is deprecated. Cast to list if needed.",
247258
DeprecationWarning,
248-
stacklevel=2,
259+
stacklevel=_pypy_partial(2),
249260
)
250261

251262
def __setitem__(self, *args, **kwargs):
@@ -394,7 +405,7 @@ class Deprecated:
394405
warnings.warn,
395406
"SelectableGroups dict interface is deprecated. Use select.",
396407
DeprecationWarning,
397-
stacklevel=2,
408+
stacklevel=_pypy_partial(2),
398409
)
399410

400411
def __getitem__(self, name):

0 commit comments

Comments
 (0)