From 75a054f7a24501aed0c4f907f6f9d7de2c016ad0 Mon Sep 17 00:00:00 2001 From: Josh Holbrook Date: Fri, 30 Aug 2024 11:38:18 -0800 Subject: [PATCH] Remove deprecated APIs (#142) * Remove deprecated APIs * Add PyeeError --- CHANGELOG.md | 9 ++++ docs/api.md | 2 - pyee/__init__.py | 108 +---------------------------------------------- pyee/base.py | 8 +++- pyee/trio.py | 10 ++--- pyee/twisted.py | 4 +- 6 files changed, 24 insertions(+), 117 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dddf15..179c3e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +- Remove deprecated imports: + - `pyee.BaseEventEmitter` + - `pyee.AsyncIOEventEmitter` + - `pyee.TwistedEventEmitter` + - `pyee.ExecutorEventEmitter` + - `pyee.TrioEventEmitter` +- Add `PyeeError` which inherits from `PyeeException`, and use throughout +- Deprecate direct use of `PyeeException` + ## 2024/08/30 Version 11.1.1 - Add project URLs to pyproject.toml and PyPI diff --git a/docs/api.md b/docs/api.md index d9142ae..e0f93e9 100644 --- a/docs/api.md +++ b/docs/api.md @@ -7,8 +7,6 @@ options: members: - EventEmitter - - BaseEventEmitter - - AsyncIOEventEmitter - PyeeException show_root_heading: false diff --git a/pyee/__init__.py b/pyee/__init__.py index 6c39c30..bb8b224 100644 --- a/pyee/__init__.py +++ b/pyee/__init__.py @@ -27,110 +27,6 @@ """ -from warnings import warn +from pyee.base import EventEmitter, PyeeError, PyeeException -from pyee.base import EventEmitter as EventEmitter -from pyee.base import PyeeException - - -class BaseEventEmitter(EventEmitter): - """ - BaseEventEmitter is deprecated and an alias for EventEmitter. - """ - - def __init__(self): - warn( - DeprecationWarning( - "pyee.BaseEventEmitter is deprecated and will be removed in a " - "future major version; you should instead use pyee.EventEmitter." - ) - ) - - super(BaseEventEmitter, self).__init__() - - -__all__ = ["BaseEventEmitter", "EventEmitter", "PyeeException"] - -try: - from pyee.asyncio import AsyncIOEventEmitter as _AsyncIOEventEmitter # noqa - - class AsyncIOEventEmitter(_AsyncIOEventEmitter): - """ - AsyncIOEventEmitter has been moved to the pyee.asyncio module. - """ - - def __init__(self, loop=None): - warn( - DeprecationWarning( - "pyee.AsyncIOEventEmitter has been moved to the pyee.asyncio " - "module." - ) - ) - super(AsyncIOEventEmitter, self).__init__(loop=loop) - - __all__.append("AsyncIOEventEmitter") -except ImportError: - pass - -try: - from pyee.twisted import TwistedEventEmitter as _TwistedEventEmitter # noqa - - class TwistedEventEmitter(_TwistedEventEmitter): - """ - TwistedEventEmitter has been moved to the pyee.twisted module. - """ - - def __init__(self): - warn( - DeprecationWarning( - "pyee.TwistedEventEmitter has been moved to the pyee.twisted " - "module." - ) - ) - super(TwistedEventEmitter, self).__init__() - - __all__.append("TwistedEventEmitter") -except ImportError: - pass - -try: - from pyee.executor import ExecutorEventEmitter as _ExecutorEventEmitter # noqa - - class ExecutorEventEmitter(_ExecutorEventEmitter): - """ - ExecutorEventEmitter has been moved to the pyee.executor module. - """ - - def __init__(self, executor=None): - warn( - DeprecationWarning( - "pyee.ExecutorEventEmitter has been moved to the pyee.executor " - "module." - ) - ) - super(ExecutorEventEmitter, self).__init__(executor=executor) - - __all__.append("ExecutorEventEmitter") -except ImportError: - pass - -try: - from pyee.trio import TrioEventEmitter as _TrioEventEmitter # noqa - - class TrioEventEmitter(_TrioEventEmitter): - """ - TrioEventEmitter has been moved to the pyee.trio module. - """ - - def __init__(self, nursery=None, manager=None): - warn( - DeprecationWarning( - "pyee.TrioEventEmitter has been moved to the pyee.trio module." - ) - ) - - super(TrioEventEmitter, self).__init__(nursery=nursery, manager=manager) - - __all__.append("TrioEventEmitter") -except (ImportError, SyntaxError): - pass +__all__ = ["EventEmitter", "PyeeError", "PyeeException"] diff --git a/pyee/base.py b/pyee/base.py index 5c2a4c2..cc1b6f9 100644 --- a/pyee/base.py +++ b/pyee/base.py @@ -17,7 +17,11 @@ class PyeeException(Exception): - """An exception internal to pyee.""" + """An exception internal to pyee. Deprecated in favor of PyeeError.""" + + +class PyeeError(PyeeException): + """An error internal to pyee.""" Handler = TypeVar("Handler", bound=Callable) @@ -168,7 +172,7 @@ def _emit_handle_potential_error(self, event: str, error: Any) -> None: if isinstance(error, Exception): raise error else: - raise PyeeException(f"Uncaught, unspecified 'error' event: {error}") + raise PyeeError(f"Uncaught, unspecified 'error' event: {error}") def _call_handlers( self, diff --git a/pyee/trio.py b/pyee/trio.py index 063404b..5a7f4f0 100644 --- a/pyee/trio.py +++ b/pyee/trio.py @@ -6,7 +6,7 @@ import trio -from pyee.base import EventEmitter, PyeeException +from pyee.base import EventEmitter, PyeeError __all__ = ["TrioEventEmitter"] @@ -59,7 +59,7 @@ def __init__( self._manager: Optional["AbstractAsyncContextManager[trio.Nursery]"] = None if nursery: if manager: - raise PyeeException( + raise PyeeError( "You may either pass a nursery or a nursery manager " "but not both" ) self._nursery = nursery @@ -89,7 +89,7 @@ def _emit_run( kwargs: Dict[str, Any], ) -> None: if not self._nursery: - raise PyeeException("Uninitialized trio nursery") + raise PyeeError("Uninitialized trio nursery") self._nursery.start_soon(self._async_runner(f, args, kwargs)) @asynccontextmanager @@ -108,7 +108,7 @@ async def context( self._nursery = nursery yield self else: - raise PyeeException("Uninitialized nursery or nursery manager") + raise PyeeError("Uninitialized nursery or nursery manager") async def __aenter__(self) -> "TrioEventEmitter": self._context: Optional[AbstractAsyncContextManager["TrioEventEmitter"]] = ( @@ -123,7 +123,7 @@ async def __aexit__( traceback: Optional[TracebackType], ) -> Optional[bool]: if self._context is None: - raise PyeeException("Attempting to exit uninitialized context") + raise PyeeError("Attempting to exit uninitialized context") rv = await self._context.__aexit__(type, value, traceback) self._context = None self._nursery = None diff --git a/pyee/twisted.py b/pyee/twisted.py index 5d46d94..9500a6b 100644 --- a/pyee/twisted.py +++ b/pyee/twisted.py @@ -5,7 +5,7 @@ from twisted.internet.defer import Deferred, ensureDeferred from twisted.python.failure import Failure -from pyee.base import EventEmitter, PyeeException +from pyee.base import EventEmitter, PyeeError try: from asyncio import iscoroutine @@ -90,7 +90,7 @@ def _emit_handle_potential_error(self, event: str, error: Any) -> None: elif isinstance(error, Exception): self.emit("error", error) else: - self.emit("error", PyeeException(f"Unexpected failure object: {error}")) + self.emit("error", PyeeError(f"Unexpected failure object: {error}")) else: (super(TwistedEventEmitter, self))._emit_handle_potential_error( event, error