Skip to content
Closed
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
6 changes: 6 additions & 0 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ def register(self, plugin: _Plugin, name: str | None = None) -> str | None:
# Registering a `None` plugin causes problems (#731). However, some
# users are doing it, so can't error out (#749). Just ignore
# instead.
warnings.warn(
"Passing None to PluginManager.register() is deprecated and will be "
"removed in a future release.",
DeprecationWarning,
stacklevel=2,
)
return None

plugin_name = name or self.get_canonical_name(plugin)
Expand Down
12 changes: 10 additions & 2 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def test_plugin_double_register(pm: PluginManager) -> None:

def test_register_ignores_none(pm: PluginManager) -> None:
"""``None`` collides with the blocked-name sentinel and must be ignored."""
assert pm.register(None) is None
with pytest.warns(
DeprecationWarning,
match=r"Passing None to PluginManager\.register\(\) is deprecated",
):
assert pm.register(None) is None
assert pm.get_plugins() == set()
assert not pm.is_registered(None)

Expand Down Expand Up @@ -1029,7 +1033,11 @@ def register(self, plugin: object, name: str | None = None) -> str | None:
monkeypatch.setattr(importlib.metadata, "distributions", lambda: (dist,))
pm = DecliningPluginManager("example")

assert pm.load_setuptools_entrypoints("hello") == 1
with pytest.warns(
DeprecationWarning,
match=r"Passing None to PluginManager\.register\(\) is deprecated",
):
assert pm.load_setuptools_entrypoints("hello") == 1
assert pm.list_plugin_distributions() == [(accepted, dist)]


Expand Down