-
Notifications
You must be signed in to change notification settings - Fork 458
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
Fix some ruff errors and simplify LICHESS_TYPE #1082
Conversation
All of the changes are good, except that I agree with your hesitation about changing the if-elif-else structures. Different ways of writing them can have extra meaning to people, even if the Python interpreter treats them the same. (Apologies for the pedantry) TL;DR: I suggest putting One thing ruff seems to really like is turning every def average1(numbers: list[float]) -> float:
if numbers:
s = sum(numbers)
n = len(numbers)
return s/n
else:
raise ValueError("Cannot find average of empty list.")
def average2(numbers: list[float]) -> float:
if numbers:
s = sum(numbers)
n = len(numbers)
return s/n
raise ValueError("Cannot find average of empty list.")
def average3(numbers: list[float]) -> float:
if not numbers:
raise ValueError("Cannot find average of empty list.")
s = sum(numbers)
n = len(numbers)
return s/n Statements in a sequence are the easiest to understand since they don't have branches or loops. So, we should place the most important parts of a function within the fewest control structures (minimizing indentation). The first function, The second function, The third function, In this PR, I would agree with the change to the if-block starting on line 283 of One change I don't agree with is this (starting on line 352 of minutes, seconds = divmod(number, 60)
if minutes >= 1:
return f"{minutes:0.0f}m {seconds:0.1f}s"
else:
return f"{seconds:0.1f}s" to minutes, seconds = divmod(number, 60)
if minutes >= 1:
return f"{minutes:0.0f}m {seconds:0.1f}s"
return f"{seconds:0.1f}s" Formatting a time duration of more than a minute is not a special case. These two cases are just different ways of handling different data and so should not be put in different structure. There is one example of an if-block that ruff thinks should be changed, but I disagree with the ruff-suggested change: lines 188 to 194 of The changes like if a:
return a_result
elif b:
return b_result
else:
return c_result to if a:
return a_result
if b:
return b_result
return c_result are fine. Use your judgement when choosing structures. |
I changed the structures to what I considered most readable. |
Type of pull request:
Description:
Fixes some ruff errors and removes them from being ignored. I'm not sure if some changes (like removing
else
afterreturn
) are beneficial, so I'm open to reverting them back.Also, makes
Lichess
intest_bot.lichess
inherit fromlib.lichess.Lichess
to simplify away theLICHESS_TYPE
variable.Related Issues:
None.
Checklist:
Screenshots/logs (if applicable):