Skip to content
Open
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
2 changes: 1 addition & 1 deletion changelog/731.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
:func:`PluginManager.register(None) <pluggy.PluginManager.register>` is now rejected early with a ``TypeError`` instead of having some weird behaviors.
:func:`PluginManager.register(None) <pluggy.PluginManager.register>` is now ignored instead of having some weird behaviors.
5 changes: 4 additions & 1 deletion src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ def register(self, plugin: _Plugin, name: str | None = None) -> str | None:
If the plugin is already registered, raises a :exc:`ValueError`.
"""
if plugin is None:
raise TypeError("plugin must not be None")
# Registering a `None` plugin causes problems (#731). However, some
# users are doing it, so can't error out (#749). Just ignore
# instead.
return None

plugin_name = name or self.get_canonical_name(plugin)

Expand Down
7 changes: 3 additions & 4 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ def test_plugin_double_register(pm: PluginManager) -> None:
pm.register(42, name="def")


def test_register_rejects_none(pm: PluginManager) -> None:
"""``None`` collides with the blocked-name sentinel and must be rejected."""
with pytest.raises(TypeError, match="plugin must not be None"):
pm.register(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
assert pm.get_plugins() == set()
assert not pm.is_registered(None)

Expand Down
Loading