Skip to content

Commit ebeb2f2

Browse files
authored
Merge pull request #471 from bluetech/unblock
Add `PluginManager.unblock` method to unblock a name
2 parents 3a28b4d + 13b3661 commit ebeb2f2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/pluggy/_manager.py

+10
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ def is_blocked(self, name: str) -> bool:
235235
"""Return whether the given plugin name is blocked."""
236236
return name in self._name2plugin and self._name2plugin[name] is None
237237

238+
def unblock(self, name: str) -> bool:
239+
"""Unblocks a name.
240+
241+
Returns whether the name was actually blocked.
242+
"""
243+
if self._name2plugin.get(name, -1) is None:
244+
del self._name2plugin[name]
245+
return True
246+
return False
247+
238248
def add_hookspecs(self, module_or_class: _Namespace) -> None:
239249
"""Add new hook specifications defined in the given ``module_or_class``.
240250

testing/test_pluginmanager.py

+7
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ class A:
110110
pm.unregister(name="somename")
111111
assert pm.is_blocked("somename")
112112

113+
# Unblock.
114+
assert not pm.unblock("someothername")
115+
assert pm.unblock("somename")
116+
assert not pm.is_blocked("somename")
117+
assert not pm.unblock("somename")
118+
assert pm.register(A(), "somename")
119+
113120

114121
def test_register_mismatch_method(he_pm: PluginManager) -> None:
115122
class hello:

0 commit comments

Comments
 (0)