Skip to content

Commit

Permalink
feat(ext.bridge): add bridge.Context as a Union class (#2106)
Browse files Browse the repository at this point in the history
* add `bridge.Context`

* style(pre-commit): auto fixes from pre-commit.com hooks

* docs and changelog

* Improve docs

* style(pre-commit): auto fixes from pre-commit.com hooks

* change docs declaration from `class` to `data`

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: plun1331 <49261529+plun1331@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 11, 2023
1 parent e5aafe4 commit 50281e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2086](https://github.com/Pycord-Development/pycord/pull/2086))
- Added new embedded activities, Gartic Phone and Jamspace.
([#2102](https://github.com/Pycord-Development/pycord/pull/2102))
- Added `bridge.Context` as a shortcut to `Union` of subclasses.
([#2106](https://github.com/Pycord-Development/pycord/pull/2106))

### Changed

Expand Down
11 changes: 9 additions & 2 deletions discord/ext/bridge/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any, overload
from typing import TYPE_CHECKING, Any, Union, overload

from discord.commands import ApplicationContext
from discord.interactions import Interaction, InteractionMessage
Expand All @@ -38,7 +38,7 @@
from .core import BridgeExtCommand, BridgeSlashCommand


__all__ = ("BridgeContext", "BridgeExtContext", "BridgeApplicationContext")
__all__ = ("BridgeContext", "BridgeExtContext", "BridgeApplicationContext", "Context")


class BridgeContext(ABC):
Expand Down Expand Up @@ -195,3 +195,10 @@ async def delete(
"""
if self._original_response_message:
await self._original_response_message.delete(delay=delay, reason=reason)


Context = Union[BridgeExtContext, BridgeApplicationContext]
"""
A Union class for either :class:`BridgeExtContext` or :class:`BridgeApplicationContext`.
Can be used as a type hint for Context for bridge commands.
"""
6 changes: 6 additions & 0 deletions docs/ext/bridge/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,9 @@ BridgeContext Subclasses

.. autoclass:: discord.ext.bridge.BridgeExtContext
:members:

.. attributetable:: discord.ext.bridge.Context

.. data:: discord.ext.bridge.Context

Alias of :data:`typing.Union` [ :class:`.BridgeExtContext`, :class:`.BridgeApplicationContext` ] for typing convenience.

0 comments on commit 50281e6

Please sign in to comment.