Skip to content

feat: add proper typing support for bridge contexts#3251

Open
AstreaTSS wants to merge 5 commits into
Pycord-Development:masterfrom
AstreaTSS:hybrid-typing
Open

feat: add proper typing support for bridge contexts#3251
AstreaTSS wants to merge 5 commits into
Pycord-Development:masterfrom
AstreaTSS:hybrid-typing

Conversation

@AstreaTSS

Copy link
Copy Markdown
Contributor

Summary

This PR adds a new function to BridgeContext and its two subclasses: typing(). In BridgeExtContext, this functions just like Context.typing, but in BridgeApplicationContext, this does a defer. This is most useful when you have a long running bridge command that lasts longer than what trigger_typing() allows.

An example (which showcases this better than any description could do) is below:

import asyncio
from discord.ext import bridge

bot = bridge.Bot(...)

@bot.bridge_command()
async def hello(ctx: bridge.Context):
    async with ctx.typing(ephemeral=True):
        await asyncio.sleep(15)
    await ctx.respond("Hello!")

This is a breaking change. ApplicationContext has a typing() function that types in the channel the command is being run, although the usefulness of this is debatable for slash commands; regardless, this overwrites that function.

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.
  • AI Usage has been disclosed.
    • If AI has been used, I understand fully what the code does

@AstreaTSS AstreaTSS requested review from a team and plun1331 June 4, 2026 03:11
@AstreaTSS AstreaTSS requested a review from Lumabots June 4, 2026 03:11
@github-project-automation github-project-automation Bot moved this to Todo in Pycord Jun 4, 2026
@pycord-app

pycord-app Bot commented Jun 4, 2026

Copy link
Copy Markdown

Thanks for opening this pull request!
Please make sure you have read the Contributing Guidelines and Code of Conduct.

This pull request can be checked-out with:

git fetch origin pull/3251/head:pr-3251
git checkout pr-3251

This pull request can be installed with:

pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3251/head

Paillat-dev
Paillat-dev previously approved these changes Jun 7, 2026

@Paillat-dev Paillat-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm although we should probably shift focus away from bridge and the exts for the time being until we conclude what to do with them

Comment on lines +156 to +162
def typing(self, *args, **kwargs) -> Typing | DeferTyping:
"""
Returns a context manager that allows you to type for an indefinite period of time.
In :class:`BridgeExtContext`, this will be :meth:`~Context.typing` while in :class:`BridgeApplicationContext`,
this is equivalent to a defer() call and does not do any typing calls.
"""
return self._typing(*args, **kwargs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need both typing and _typing ?

@vmphase vmphase Jun 7, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the template method pattern already used by respond, defer and others throughout the file.

Comment thread discord/ext/bridge/context.py Outdated
Comment thread discord/ext/bridge/context.py Outdated
@Paillat-dev Paillat-dev added this to the 2.9.0rc1 milestone Jun 7, 2026
@AstreaTSS

Copy link
Copy Markdown
Contributor Author

(Actionable) reviews have been addressed! As for shifting focus, that's understandable. This was just meant to be a quick PR for a simple thing at the end of the day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants