Skip to content

Start applying Pylint rules (PLR) - #436

Merged
hugovk merged 3 commits into
prettytable:mainfrom
DimitriPapadopoulos:PLR
Jan 20, 2026
Merged

hugovk merged 3 commits into
prettytable:mainfrom
DimitriPapadopoulos:PLR

Conversation

@DimitriPapadopoulos

Copy link
Copy Markdown
Contributor

I have not applied these Refactor rules:

@codecov

codecov Bot commented Jan 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
macos-latest 97.35% <100.00%> (+1.37%) ⬆️
ubuntu-latest 97.35% <100.00%> (+1.37%) ⬆️
windows-latest 97.32% <100.00%> (+1.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/prettytable/prettytable.py 95.32% <100.00%> (+2.20%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this else is also obsolete

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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**'
>>> 

@stuertz stuertz Jan 18, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) * " "

@DimitriPapadopoulos DimitriPapadopoulos Jan 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I do kind of prefer that symmetry, it can be easier to read.

@stuertz stuertz added the changelog: skip Exclude PR from release draft label Jan 18, 2026
Replace `if` statement with `max`
Use `elif` instead of `else` then `if`, to reduce indentation
@DimitriPapadopoulos

Copy link
Copy Markdown
Contributor Author

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 hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/prettytable/prettytable.py Outdated
Comment on lines +900 to +904
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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: skip Exclude PR from release draft

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants