Skip to content

Conversation

@zephyr-i
Copy link

@zephyr-i zephyr-i commented Dec 1, 2025

Type of changes

  • [ X ] Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • [ X ] I've run the latest black with default args on new code.
  • [ X ] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate (see note about typos above).
  • [ X ] I've added tests for new code.
  • [ X ] I accept that @willmcgugan may be pedantic in the code review.

Description

The _get_padding_width() method was not considering the pad_edge setting when calculating column widths. This caused inconsistency between:

  • Width calculation: Included left padding for first column
  • Rendering: Excluded left padding when pad_edge=False

This resulted in the first column being sized larger than necessary, causing misalignment.

Changes

  • rich/table.py: Fixed _get_padding_width() method
  • tests/test_table.py: Added new tests for specific scenarios
  • tests/test_columns.py: Updated expected output (now correct)
  • CHANGELOG.md: Added fix entry

Testing

Manual test with issue example passes
All table/column tests pass

Note on Pre-existing Test Failures

The following 4 tests were already failing (locally) before this fix:

  • tests/test_log.py::test_log
  • tests/test_markdown.py::test_inline_code
  • tests/test_syntax.py::test_blank_lines
  • tests/test_syntax.py::test_python_render_simple_indent_guides

These are unrelated to this change.

Impact

The _get_padding_width() method was not considering the pad_edge
setting, causing inconsistency between width calculation and actual
rendering. When pad_edge=False, the first column was sized with full
padding but rendered without left padding, resulting in misaligned
tables.

This fix adds pad_edge logic to _get_padding_width() to ensure
consistency between measurement and rendering.

Changes:
- Updated _get_padding_width() to respect pad_edge setting
- Added logic to exclude left padding for first column when pad_edge=False
- Added logic to exclude right padding for last column when pad_edge=False
- Updated test_columns.py expected output to reflect corrected behavior

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Table padding is miscalculated in first column

1 participant