jazzband / prettytable

Display tabular data in a visually appealing ASCII table format
https://pypi.org/project/PrettyTable/
Other
1.35k stars 154 forks source link

Alignment alteration #207

Open myheroyuki opened 1 year ago

myheroyuki commented 1 year ago

Here's a possible solution to a batch of issues with column alignment (#202, #199 , #102, #111). The root of these issues seemed to be the fact that the align attribute was filling two roles. It was a global alignment, set as a string, and also a per-column alignment, set as a dictionary. I fixed this by creating a new Alignment class that is basically a dictionary that contains a variable that stores the global alignment value.

The main reason I decided to break it out into it's own single class was that having it as a class allowed me to validate the attributes when the user sets it per column using square brackets. It still functions the same way for the user when they set it, update it, print it, or iterate over it, but it changes the return type to be an instance of Alignment rather than dict.

I'd really like to get some comments on this one with some ideas on how I can improve it. I don't love the solution I came up with here, but other things I thought of either would change things from the user's perspective, not address all the issues, or make the code more confusing.

codecov[bot] commented 1 year ago

Codecov Report

Merging #207 (96d6a4e) into main (ed5d66c) will increase coverage by 0.61%. The diff coverage is 97.71%.

@@            Coverage Diff             @@
##             main     #207      +/-   ##
==========================================
+ Coverage   94.38%   95.00%   +0.61%     
==========================================
  Files           5        5              
  Lines        2281     2421     +140     
==========================================
+ Hits         2153     2300     +147     
+ Misses        128      121       -7     
Flag Coverage Δ
macos-latest 94.96% <97.71%> (+0.70%) :arrow_up:
ubuntu-latest 94.96% <97.71%> (+0.61%) :arrow_up:
windows-latest 94.91% <97.71%> (+0.61%) :arrow_up:

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

Impacted Files Coverage Δ
src/prettytable/prettytable.py 91.60% <96.03%> (+0.91%) :arrow_up:
tests/test_colortable.py 100.00% <100.00%> (ø)
tests/test_prettytable.py 100.00% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more