diff --git a/changelog/731.bugfix.rst b/changelog/731.bugfix.rst index e874a1e8..660684bc 100644 --- a/changelog/731.bugfix.rst +++ b/changelog/731.bugfix.rst @@ -1 +1 @@ -:func:`PluginManager.register(None) ` is now rejected early with a ``TypeError`` instead of having some weird behaviors. +:func:`PluginManager.register(None) ` is now ignored instead of having some weird behaviors. diff --git a/src/pluggy/_manager.py b/src/pluggy/_manager.py index 1d7984a9..3739dc8f 100644 --- a/src/pluggy/_manager.py +++ b/src/pluggy/_manager.py @@ -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) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 7e5058b2..0c17418f 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -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)