Skip to content

refactor: ♻️ Refactor weird checks in CogMeta and fix some typing and other qol things #2730

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

Paillat-dev
Copy link
Contributor

@Paillat-dev Paillat-dev commented Mar 4, 2025

Summary

Changes made:

  • Added typing for SlashCommand.parent
  • Added BridgeCommand.__bridge__ which is True
  • Replaced weird checks to assess something is a BridgeCommand by checking it has an add_to attribute (BridgeCommand is the only class in py-cord that has such method) with a TypeGuard that checks it has a __bridge__ attribute (which also makes this typed and that's cool)
  • Fixed typing of CogMeta.__cog_commands__
  • Rename name_filter to _name_filter and define it outside of __new__ to avoid redefining it every time and also avoid assigning a lambda to a variable.
  • Extract name validation logic (disallow the bot_ or cog_ prefixes) to a helper function _validate_name_prefix.
  • Extract class attributes iteration and processing to helper function _process_attributes. Simplify it by changing overengineered checks and simplifying dead code. Rename elem, value to attr_name, attr_value
  • Extract command update logic to _update_command, idem as above.
  • Import Generator & Mapping from collections.abc instead of typing (deprecated since python 3.9).

Tested and fixed all the issues I found, but it would be nice if someone else could also test this to make sure I didn't miss anything.

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.

@Paillat-dev Paillat-dev changed the title refactor: Refactor weird checks in CogMeta and fix some typing refactor: Refactor weird checks in CogMeta and fix some typing and other qol things Mar 4, 2025
@Paillat-dev Paillat-dev changed the title refactor: Refactor weird checks in CogMeta and fix some typing and other qol things refactor: ♻️ Refactor weird checks in CogMeta and fix some typing and other qol things Mar 4, 2025
@Paillat-dev Paillat-dev marked this pull request as ready for review March 9, 2025 18:11
@Paillat-dev Paillat-dev requested review from a team as code owners March 9, 2025 18:11
@pullapprove4 pullapprove4 bot requested a review from Lulalaby March 9, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant