Skip to content

Commit

Permalink
Adjust for variable stacklevel on partial calls in PyPy. Fixes #327.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 5, 2021
1 parent b49cdaa commit 596155c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
@@ -1,3 +1,9 @@
v4.6.1
======

* #327: Deprecation warnings now honor call stack variance
on PyPy.

v4.6.0
======

Expand Down
15 changes: 13 additions & 2 deletions importlib_metadata/__init__.py
Expand Up @@ -7,6 +7,7 @@
import email
import pathlib
import operator
import platform
import textwrap
import warnings
import functools
Expand Down Expand Up @@ -48,6 +49,16 @@
]


def _pypy_partial(val):
"""
Adjust for variable stacklevel on partial under PyPy.
Workaround for #327.
"""
is_pypy = platform.python_implementation() == 'PyPy'
return val + is_pypy


class PackageNotFoundError(ModuleNotFoundError):
"""The package was not found."""

Expand Down Expand Up @@ -245,7 +256,7 @@ class DeprecatedList(list):
warnings.warn,
"EntryPoints list interface is deprecated. Cast to list if needed.",
DeprecationWarning,
stacklevel=2,
stacklevel=_pypy_partial(2),
)

def __setitem__(self, *args, **kwargs):
Expand Down Expand Up @@ -394,7 +405,7 @@ class Deprecated:
warnings.warn,
"SelectableGroups dict interface is deprecated. Use select.",
DeprecationWarning,
stacklevel=2,
stacklevel=_pypy_partial(2),
)

def __getitem__(self, name):
Expand Down

0 comments on commit 596155c

Please sign in to comment.