Repository navigation
Start applying Pylint rules (PLR) - #436
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
| if _str_block_width(text) % 2: | ||
| return (excess // 2) * " " + text + (excess // 2 + 1) * " " | ||
| # and more space on left if text is of even length | ||
| else: |
There was a problem hiding this comment.
I think this else is also obsolete
There was a problem hiding this comment.
Why is it obsolete? In any case, str.center still behaves like this:
>>> excess = 5
>>>
>>> odd_length = "12345"
>>> width = excess + len(odd_length)
>>> odd_length.center(width, '*')
'**12345***'
>>>
>>> even_length = "123456"
>>> width = excess + len(even_length)
>>> even_length.center(width, '*')
'***123456**'
>>> There was a problem hiding this comment.
I meant this else
if _str_block_width(text) % 2:
return (excess // 2) * " " + text + (excess // 2 + 1) * " "
else:
return (excess // 2 + 1) * " " + text + (excess // 2) * " "can be changed to
if _str_block_width(text) % 2:
return (excess // 2) * " " + text + (excess // 2 + 1) * " "
return (excess // 2 + 1) * " " + text + (excess // 2) * " "There was a problem hiding this comment.
Got it. This would be enforced by the Ruff rule superfluous-else-return (RET505), which I haven't applied so far because some maintainers find the resulting less readable (lacking symmetry).
How about enforcing RET rules in a different PR?
There was a problem hiding this comment.
Yeah, I do kind of prefer that symmetry, it can be easier to read.
Replace `if` statement with `max`
Use `elif` instead of `else` then `if`, to reduce indentation
|
I'm sorry, I slightly changed the first commit because of an oversight, I hadn't noticed you had started looking into the PR. |
hugovk
left a comment
There was a problem hiding this comment.
I've run pylint on projects before and applied some of the fixes, but never added it to the lint/CI before, because I felt some of the warnings weren't an improvement.
These look okay, with one suggestion.
| elif not self._field_names: | ||
| self._align = {BASE_ALIGN_VALUE: "c"} | ||
| else: | ||
| if not self._field_names: | ||
| self._align = {BASE_ALIGN_VALUE: "c"} | ||
| else: | ||
| for field in self._field_names: | ||
| self._align[field] = "c" | ||
| for field in self._field_names: | ||
| self._align[field] = "c" |
There was a problem hiding this comment.
Let's flip the condition first before flattening, to remove a not:
elif self._field_names:
for field in self._field_names:
self._align[field] = "c"
else:
self._align = {BASE_ALIGN_VALUE: "c"}
I have not applied these Refactor rules: