-
-
Notifications
You must be signed in to change notification settings - Fork 494
refactor: remaining 3.10+ cleanup #3323
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
base: master
Are you sure you want to change the base?
Changes from all commits
57f1fa3
44cc4f2
acfd8be
6793990
a817dc4
9e4d152
e3e2e08
d586f18
fea27ed
6a47334
b0d09ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -536,49 +536,49 @@ def category(self) -> AuditLogActionCategory | None: | |
|
|
||
| @property | ||
| def target_type(self) -> str | None: | ||
| v = self.value | ||
| if v == -1: | ||
| return "all" | ||
| elif v < 10: | ||
| return "guild" | ||
| elif v < 20: | ||
| return "channel" | ||
| elif v < 30: | ||
| return "user" | ||
| elif v < 40: | ||
| return "role" | ||
| elif v < 50: | ||
| return "invite" | ||
| elif v < 60: | ||
| return "webhook" | ||
| elif v < 70: | ||
| return "emoji" | ||
| elif v == 73: | ||
| return "channel" | ||
| elif v < 80: | ||
| return "message" | ||
| elif v < 83: | ||
| return "integration" | ||
| elif v < 90: | ||
| return "stage_instance" | ||
| elif v < 93: | ||
| return "sticker" | ||
| elif v < 103: | ||
| return "scheduled_event" | ||
| elif v < 113: | ||
| return "thread" | ||
| elif v < 122: | ||
| return "application_command_permission" | ||
| elif v < 146: | ||
| return "auto_moderation_rule" | ||
| elif v < 152: | ||
| return "monetization" | ||
| elif v < 168: | ||
| return "onboarding" | ||
| elif v < 192: | ||
| return "server_guide" | ||
| elif v < 194: | ||
| return "voice_channel_status" | ||
| match self.value: | ||
| case -1: | ||
| return "all" | ||
| case v if v < 10: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also imo this hurts readability since it's not proper equivalence.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mostly went for it since it removes the repeated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid sure but this is more confusing in this case. In my mind case x if is for specific edge cases, not 99% of the conditions. In this case it is just more messy.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not an actual convention and I think this comes down to preference rather than a correctness. Nothing in PEP63* suggests guards should stay rare relative to structural cases, and for a scalar subject like this there's no structural pattern to lean on in the first place, so guard-per-case is just what matching an int naturally looks like.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course it's preference. |
||
| return "guild" | ||
| case v if v < 20: | ||
| return "channel" | ||
| case v if v < 30: | ||
| return "user" | ||
| case v if v < 40: | ||
| return "role" | ||
| case v if v < 50: | ||
| return "invite" | ||
| case v if v < 60: | ||
| return "webhook" | ||
| case v if v < 70: | ||
| return "emoji" | ||
| case 73: | ||
| return "channel" | ||
| case v if v < 80: | ||
| return "message" | ||
| case v if v < 83: | ||
| return "integration" | ||
| case v if v < 90: | ||
| return "stage_instance" | ||
| case v if v < 93: | ||
| return "sticker" | ||
| case v if v < 103: | ||
| return "scheduled_event" | ||
| case v if v < 113: | ||
| return "thread" | ||
| case v if v < 122: | ||
| return "application_command_permission" | ||
| case v if v < 146: | ||
| return "auto_moderation_rule" | ||
| case v if v < 152: | ||
| return "monetization" | ||
| case v if v < 168: | ||
| return "onboarding" | ||
| case v if v < 192: | ||
| return "server_guide" | ||
| case v if v < 194: | ||
| return "voice_channel_status" | ||
|
|
||
|
|
||
| class UserFlags(Enum): | ||
|
|
@@ -840,11 +840,10 @@ def from_datatype(cls, datatype): | |
| else: | ||
| raise TypeError("Invalid usage of typing.Union") | ||
|
|
||
| py_3_10_union_type = hasattr(types, "UnionType") and isinstance( | ||
| datatype, types.UnionType | ||
| ) | ||
|
|
||
| if py_3_10_union_type or getattr(datatype, "__origin__", None) is Union: | ||
| if ( | ||
| isinstance(datatype, types.UnionType) | ||
| or getattr(datatype, "__origin__", None) is Union | ||
| ): | ||
| # Python 3.10+ "|" operator or typing.Union has been used. The __args__ attribute is a tuple of the types. | ||
| # Type checking fails for this case, so ignore it. | ||
| return cls.from_datatype(datatype.__args__) # type: ignore | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.