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

feat: don't parse self/ctx parameter annotations of prefix command callbacks #847

Merged
merged 20 commits into from
Nov 16, 2023

Conversation

shiftinv
Copy link
Member

@shiftinv shiftinv commented Nov 2, 2022

Summary

get_signature_parameters would previously evaluate annotations of all parameters, including self/ctx, which doesn't allow for code like this:

...
if TYPE_CHECKING:
    from .my_bot import MyBot

class SomeCog(Cog):
    @commands.command()
    async def cmd(self, ctx: Context["MyBot"], stuff: str):
        ...

Admittedly, that pattern may be rare, but due to this issue a workaround was required in #828.
This PR avoids parsing the annotations of the self (if present) and ctx parameter entirely, as they're not relevant for the process.

Checklist

  • If code changes were made, then they have been tested
    • I have updated the documentation to reflect the changes
    • I have formatted the code properly by running task lint
    • I have type-checked the code by running task pyright
  • 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, ...)

@shiftinv shiftinv added t: enhancement New feature s: needs review Issue/PR is awaiting reviews t: bugfix labels Nov 2, 2022
@shiftinv shiftinv added this to the disnake v2.8 milestone Nov 2, 2022
@shiftinv shiftinv removed this from the disnake v2.8 milestone Feb 5, 2023
@onerandomusername onerandomusername self-requested a review February 20, 2023 05:44
@onerandomusername
Copy link
Member

@shiftinv would you please resolve conflicts?

disnake/utils.py Outdated Show resolved Hide resolved
@shiftinv shiftinv force-pushed the feat/skip-param-parsing branch from d6e7034 to fdee363 Compare November 6, 2023 20:56
Copy link
Member

@EQUENOS EQUENOS left a comment

Choose a reason for hiding this comment

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

Looks good, tests were successful

@shiftinv shiftinv enabled auto-merge (squash) November 16, 2023 14:33
@shiftinv shiftinv merged commit 2c85e39 into master Nov 16, 2023
27 checks passed
@shiftinv shiftinv deleted the feat/skip-param-parsing branch November 16, 2023 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: needs review Issue/PR is awaiting reviews t: bugfix t: enhancement New feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants