pycord
pycord copied to clipboard
refactor: :recycle: Refactor weird checks in `CogMeta` and fix some typing and other qol things
Summary
Changes made:
- Added typing for
SlashCommand.parent - Added
BridgeCommand.__bridge__which isTrue - Replaced weird checks to assess something is a
BridgeCommandby checking it has anadd_toattribute (BridgeCommandis the only class in py-cord that has such method) with aTypeGuardthat checks it has a__bridge__attribute (which also makes this typed and that's cool) - Fixed typing of
CogMeta.__cog_commands__ - Rename
name_filterto_name_filterand 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_orcog_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. Renameelem, valuetoattr_name, attr_value - Extract command update logic to
_update_command, idem as above. - Import
Generator&Mappingfromcollections.abcinstead oftyping(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.
- [x] If code changes were made then they have been tested.
- [ ] I have updated the documentation to reflect the changes.
- [ ] If
type: ignorecomments were used, a comment is also left explaining why. - [ ] I have updated the changelog to include these changes.