Skip to content

Commit

Permalink
Remove deprecated APIs (#142)
Browse files Browse the repository at this point in the history
* Remove deprecated APIs

* Add PyeeError
  • Loading branch information
jfhbrook authored Aug 30, 2024
1 parent 350e742 commit 75a054f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 117 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
options:
members:
- EventEmitter
- BaseEventEmitter
- AsyncIOEventEmitter
- PyeeException
show_root_heading: false

Expand Down
108 changes: 2 additions & 106 deletions pyee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
8 changes: 6 additions & 2 deletions pyee/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions pyee/trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import trio

from pyee.base import EventEmitter, PyeeException
from pyee.base import EventEmitter, PyeeError

__all__ = ["TrioEventEmitter"]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"]] = (
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pyee/twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 75a054f

Please sign in to comment.