Conversation
unregister() looks hookcallers up by plugin but deletes the registry entry by name, and never checked that the two agree. Passing a plugin registered as "first" together with name="second" therefore stripped the plugin's own implementations while dropping an unrelated plugin's registry entry — leaving that plugin reported as unregistered with its implementations still on the hook caller. The docstring already says "If both are specified, they must agree", so raise before mutating anything.
The spec body is never executed, so it was the one uncovered line this diff added, and it dragged Codecov's patch coverage to 96%. The .coveragerc already excludes '`- `...`' spec bodies and three other tests in this file use one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PluginManager.unregister()documents that its two ways of naming a plugin are interchangeable, and that they must agree:They do not have to agree today, and the mismatch does not fail — it produces a state that is wrong in two directions at once, because
unregisterlooks hook callers up bypluginbut deletes the registry entry byname. Sopm.unregister(plugin=first, name="second")stripsfirst's implementations and dropssecondfrom the registry. Running that on012fd24:secondis simultaneously not registered and still being called, andfirstis registered with nothing left to run.The fix is an early guard, before anything is mutated:
It raises rather than silently preferring one of the two, because the docstring already requires agreement and pluggy already raises
ValueErrorfromregister()on the analogous mismatch. It converts a silent wrong state into a loud error, not the reverse. Theregistered_name is not Noneclause keeps the existing behavior for an unregistered plugin, whichtest_unregister_blockedrelies on when it unregisters a blocked plugin twice.Tests
test_unregister_plugin_and_name_must_agreeregisters two plugins under distinct names, asserts theValueError, and then asserts that the rejected call changed no state — both plugins still registered, both implementations still on the hook caller.On
012fd24it fails withFailed: DID NOT RAISE ValueError;testing/test_pluginmanager.pyis 74 passed here against 73 there, and the full suite is 203 passed against 202 passed on012fd24— the new test, no regressions.Gates, matching what pre-commit runs:
ruff checkandruff format --checkclean on both files, andmypy src/pluggy testingreportsSuccess: no issues found in 24 source filesboth before and after the change. I did not run pre-commit itself, since it installs its own environments.I found no prior art: searching for
unregisterplusplugin/name/must agree/mismatch/ValueErrorturns up #52, #648, #740, #734, #431, #718 and #122, none about the two arguments disagreeing, and none of the 7 open PRs touches this.git logon the path showsunregisteruntouched by any recent commit, so this reads as long-standing rather than a regression — the deepergit log -S/blamearchaeology is limited because this is a--filter=blob:nonepartial clone whose older promisor blobs are not local.Left alone:
docs/index.rst:598-602says a hookimpl argument with a default is "not passed by pluggy, even when the hook caller provides a value", contradicting both the 1.7 "Hookimpl argument defaults" section and what_multicalldoes. That is a stale-doc bug, worth its own change.