Skip to content

Commit

Permalink
Move workaround for #327 to _compat module
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 31, 2021
1 parent 5583567 commit 7c74b50
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
@@ -1,3 +1,8 @@
v4.6.3
======

* Moved workaround for #327 to ``_compat`` module.

v4.6.2
======

Expand Down
16 changes: 3 additions & 13 deletions importlib_metadata/__init__.py
Expand Up @@ -7,7 +7,6 @@
import email
import pathlib
import operator
import platform
import textwrap
import warnings
import functools
Expand All @@ -21,6 +20,7 @@
NullFinder,
PyPy_repr,
install,
pypy_partial,
)
from ._functools import method_cache
from ._itertools import unique_everseen
Expand Down Expand Up @@ -49,16 +49,6 @@
]


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 @@ -256,7 +246,7 @@ class DeprecatedList(list):
warnings.warn,
"EntryPoints list interface is deprecated. Cast to list if needed.",
DeprecationWarning,
stacklevel=_pypy_partial(2),
stacklevel=pypy_partial(2),
)

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

def __getitem__(self, name):
Expand Down
11 changes: 11 additions & 0 deletions importlib_metadata/_compat.py
@@ -1,4 +1,5 @@
import sys
import platform


__all__ = ['install', 'NullFinder', 'PyPy_repr', 'Protocol']
Expand Down Expand Up @@ -84,3 +85,13 @@ def make_param(name):
if affected: # pragma: nocover
__repr__ = __compat_repr__
del affected


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

0 comments on commit 7c74b50

Please sign in to comment.