refactor: remaining 3.10+ cleanup - #3323
Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/3323/head:pr-3323
git checkout pr-3323This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3323/head |
|
I didn't update the changelog because all the changes are internal. |
| match self.value: | ||
| case -1: | ||
| return "all" | ||
| case v if v < 10: |
There was a problem hiding this comment.
Also imo this hurts readability since it's not proper equivalence.
There was a problem hiding this comment.
I mostly went for it since it removes the repeated elif v < boilerplate. Under the hood this compiles to the same sequential guard evaluation as the if-elif chain, so there's no difference. I think the reduced repetition is worth it here, and PEP 634 explicitly documents guard clauses (case x if ...) as valid usage.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8586889 to
fea27ed
Compare
Summary
Follow-up cleanup to the automated
pyupgrade --py310-pluspass in #2988, covering things that tool didn't handle:typing_extensions.ParamSpecwithtyping.ParamSpectyping.Deque/Deque[...]withcollections.deque/deque[...]collections.OrderedDictwith plaindict(insertion-orderguaranteed since 3.7)hasattr(types, "UnionType")guardif/elifchain tomatch/casePY_310version check, pre-3.10 branch,utils.flatten_literal_paramsandutils.classpropertyInformation
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.