Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated code #172

Merged
merged 3 commits into from
Oct 1, 2024
Merged
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
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Version 1.9.0
-------------

Unreleased

- Remove previously deprecated ``__version__``, ``receiver_connected``,
``Signal.temporarily_connected_to`` and ``WeakNamespace``. :pr:`172`


Version 1.8.2
-------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "blinker"
version = "1.8.2"
version = "1.9.0"
description = "Fast, simple object-to-object and broadcast signaling"
readme = "README.md"
license = { file = "LICENSE.txt" }
Expand Down
43 changes: 0 additions & 43 deletions src/blinker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import typing as t

from .base import ANY
from .base import default_namespace
from .base import NamedSignal
Expand All @@ -17,44 +15,3 @@
"Signal",
"signal",
]


def __getattr__(name: str) -> t.Any:
import warnings

if name == "__version__":
import importlib.metadata

warnings.warn(
"The '__version__' attribute is deprecated and will be removed in"
" Blinker 1.9.0. Use feature detection or"
" 'importlib.metadata.version(\"blinker\")' instead.",
DeprecationWarning,
stacklevel=2,
)
return importlib.metadata.version("blinker")

if name == "receiver_connected":
from .base import _receiver_connected

warnings.warn(
"The global 'receiver_connected' signal is deprecated and will be"
" removed in Blinker 1.9. Use 'Signal.receiver_connected' and"
" 'Signal.receiver_disconnected' instead.",
DeprecationWarning,
stacklevel=2,
)
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)
105 changes: 0 additions & 105 deletions src/blinker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import collections.abc as c
import typing as t
import warnings
import weakref
from collections import defaultdict
from contextlib import AbstractContextManager
from contextlib import contextmanager
from functools import cached_property
from inspect import iscoroutinefunction
from weakref import WeakValueDictionary

from ._utilities import make_id
from ._utilities import make_ref
Expand Down Expand Up @@ -139,15 +136,6 @@ def connect(self, receiver: F, sender: t.Any = ANY, weak: bool = True) -> F:
self.disconnect(receiver, sender)
raise

if _receiver_connected.receivers and self is not _receiver_connected:
try:
_receiver_connected.send(
self, receiver_arg=receiver, sender_arg=sender, weak_arg=weak
)
except TypeError:
self.disconnect(receiver, sender)
raise

return receiver

def connect_via(self, sender: t.Any, weak: bool = False) -> c.Callable[[F], F]:
Expand Down Expand Up @@ -213,24 +201,6 @@ def muted(self) -> c.Generator[None, None, None]:
finally:
self.is_muted = False

def temporarily_connected_to(
self, receiver: c.Callable[..., t.Any], sender: t.Any = ANY
) -> AbstractContextManager[None]:
"""Deprecated alias for :meth:`connected_to`.

.. deprecated:: 1.1
Renamed to ``connected_to``. Will be removed in Blinker 1.9.

.. versionadded:: 0.9
"""
warnings.warn(
"'temporarily_connected_to' is renamed to 'connected_to'. The old name is"
" deprecated and will be removed in Blinker 1.9.",
DeprecationWarning,
stacklevel=2,
)
return self.connected_to(receiver, sender)

def send(
self,
sender: t.Any | None = None,
Expand Down Expand Up @@ -488,23 +458,6 @@ def _clear_state(self) -> None:
self._by_receiver.clear()


_receiver_connected = Signal(
"""\
Sent by a :class:`Signal` after a receiver connects.

:argument: the Signal that was connected to
:keyword receiver_arg: the connected receiver
:keyword sender_arg: the sender to connect to
:keyword weak_arg: true if the connection to receiver_arg is a weak reference

.. deprecated:: 1.2
Individual signals have their own :attr:`~Signal.receiver_connected` and
:attr:`~Signal.receiver_disconnected` signals with a slightly simplified
call signature. This global signal will be removed in Blinker 1.9.
"""
)


class NamedSignal(Signal):
"""A named generic notification emitter. The name is not used by the signal
itself, but matches the key in the :class:`Namespace` that it belongs to.
Expand Down Expand Up @@ -551,41 +504,6 @@ def signal(self, name: str, doc: str | None = None) -> NamedSignal:
return self[name]


class _WeakNamespace(WeakValueDictionary): # type: ignore[type-arg]
"""A weak mapping of names to signals.

Automatically cleans up unused signals when the last reference goes out
of scope. This namespace implementation provides similar behavior to Blinker
<= 1.2.

.. deprecated:: 1.3
Will be removed in Blinker 1.9.

.. versionadded:: 1.3
"""

def __init__(self) -> None:
warnings.warn(
"'WeakNamespace' is deprecated and will be removed in Blinker 1.9."
" Use 'Namespace' instead.",
DeprecationWarning,
stacklevel=2,
)
super().__init__()

def signal(self, name: str, doc: str | None = None) -> NamedSignal:
"""Return the :class:`NamedSignal` for the given ``name``, creating it
if required. Repeated calls with the same name return the same signal.

:param name: The name of the signal.
:param doc: The docstring of the signal.
"""
if name not in self:
self[name] = NamedSignal(name, doc)

return self[name] # type: ignore[no-any-return]


default_namespace: Namespace = Namespace()
"""A default :class:`Namespace` for creating named signals. :func:`signal`
creates a :class:`NamedSignal` in this namespace.
Expand All @@ -596,26 +514,3 @@ def signal(self, name: str, doc: str | None = None) -> NamedSignal:
``name``, creating it if required. Repeated calls with the same name return the
same signal.
"""


def __getattr__(name: str) -> t.Any:
if name == "receiver_connected":
warnings.warn(
"The global 'receiver_connected' signal is deprecated and will be"
" removed in Blinker 1.9. Use 'Signal.receiver_connected' and"
" 'Signal.receiver_disconnected' instead.",
DeprecationWarning,
stacklevel=2,
)
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,
)
return _WeakNamespace

raise AttributeError(name)