Skip to content

Commit c3d4d8d

Browse files
Refactor imports to ensure DistFacade is only imported when TYPE_CHECKING; update versionadded for list_plugin_distributions() method
1 parent c515d46 commit c3d4d8d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/pluggy/_manager.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from . import _tracing
1717
from ._callers import _multicall
18-
from ._compat import DistFacade
1918
from ._hooks import _HookImplFunction
2019
from ._hooks import _Namespace
2120
from ._hooks import _Plugin
@@ -32,6 +31,8 @@
3231
if TYPE_CHECKING:
3332
import importlib.metadata
3433

34+
from ._compat import DistFacade
35+
3536

3637
_BeforeTrace: TypeAlias = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]
3738
_AfterTrace: TypeAlias = Callable[
@@ -416,6 +417,9 @@ def list_plugin_distinfo(self) -> list[tuple[_Plugin, DistFacade]]:
416417
Use the modern :meth:`list_plugin_distributions` method to get
417418
unwrapped :class:`importlib.metadata.Distribution` objects.
418419
"""
420+
421+
from ._compat import DistFacade
422+
419423
return [(plugin, DistFacade(dist)) for plugin, dist in self._plugin_distinfo]
420424

421425
def list_plugin_distributions(
@@ -424,10 +428,7 @@ def list_plugin_distributions(
424428
"""Return a list of (plugin, distribution) pairs for all plugins
425429
loaded via entry points.
426430
427-
Returns modern :class:`importlib.metadata.Distribution` objects without
428-
the legacy pkg_resources compatibility layer.
429-
430-
.. versionadded:: 1.6
431+
.. versionadded:: 1.7
431432
"""
432433
return list(self._plugin_distinfo)
433434

testing/test_pluginmanager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pluggy import HookspecMarker
1313
from pluggy import PluginManager
1414
from pluggy import PluginValidationError
15+
from pluggy._compat import DistFacade
1516

1617

1718
hookspec = HookspecMarker("example")
@@ -583,7 +584,9 @@ class NoHooks:
583584
pm.add_hookspecs(NoHooks)
584585

585586

586-
def test_load_setuptools_instantiation(monkeypatch, pm: PluginManager) -> None:
587+
def test_load_setuptools_instantiation(
588+
monkeypatch: pytest.MonkeyPatch, pm: PluginManager
589+
) -> None:
587590
class EntryPoint:
588591
name = "myname"
589592
group = "hello"
@@ -626,7 +629,6 @@ def my_distributions():
626629
assert ret_modern[0][1] == dist # type: ignore[comparison-overlap]
627630

628631
# Verify the old API wraps with DistFacade while new API doesn't
629-
from pluggy._compat import DistFacade
630632

631633
assert isinstance(ret[0][1], DistFacade)
632634
assert not isinstance(ret_modern[0][1], DistFacade)

0 commit comments

Comments
 (0)