Skip to content

Commit

Permalink
deprecate WeakNamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Apr 27, 2024
1 parent 783c338 commit 1a29708
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
11 changes: 2 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,9 @@ Basic Signals
Named Signals
+++++++++++++

.. function:: signal(name, doc=None)
.. autofunction:: signal

Return the :class:`NamedSignal` *name*, creating it if required.

Repeated calls to this function will return the same signal object.
Signals are created in a global :class:`Namespace`.
.. autodata:: default_namespace

.. autoclass:: NamedSignal
:show-inheritance:
Expand All @@ -386,10 +383,6 @@ Named Signals
:show-inheritance:
:members: signal

.. autoclass:: WeakNamespace
:show-inheritance:
:members: signal


Changes
=======
Expand Down
13 changes: 11 additions & 2 deletions src/blinker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .base import Namespace
from .base import Signal
from .base import signal
from .base import WeakNamespace

__all__ = [
"ANY",
Expand All @@ -17,7 +16,6 @@
"Namespace",
"Signal",
"signal",
"WeakNamespace",
]


Expand Down Expand Up @@ -48,4 +46,15 @@ def __getattr__(name: str) -> t.Any:
)
return _receiver_connected

if name == "WeakNamespace":
from .base import _WeakNamespace

warnings.warn(
"'WeakNamespace' is deprecated and will be removed in Blinker 1.9."
" Use 'Namespace' instead.",
DeprecationWarning,
stacklevel=2,
)
return _WeakNamespace

raise AttributeError(name)
16 changes: 12 additions & 4 deletions src/blinker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def signal(self, name: str, doc: str | None = None) -> NamedSignal:
return result # type: ignore[no-any-return]


class WeakNamespace(WeakValueDictionary): # type: ignore[type-arg]
class _WeakNamespace(WeakValueDictionary): # type: ignore[type-arg]
"""A weak mapping of signal names to signals.
Automatically cleans up unused Signals when the last reference goes out
Expand Down Expand Up @@ -560,12 +560,12 @@ def signal(self, name: str, doc: str | None = None) -> NamedSignal:

default_namespace = Namespace()
"""A default namespace for creating named signals. :func:`signal` creates a
signal in this namespace.
:class:`NamedSignal` in this namespace.
"""

signal = default_namespace.signal
"""Create a named signal in :data:`default_namespace`. Repeated calls with
the same name will return the same signal.
"""Create a :class:`NamedSignal` in :data:`default_namespace`. Repeated calls
with the same name will return the same signal.
"""


Expand All @@ -580,4 +580,12 @@ def __getattr__(name: str) -> t.Any:
)
return _receiver_connected

if name == "WeakNamespace":
warnings.warn(
"'WeakNamespace' is deprecated and will be removed in Blinker 1.9."
" Use 'Namespace' instead.",
DeprecationWarning,
stacklevel=2,
)

raise AttributeError(name)

0 comments on commit 1a29708

Please sign in to comment.