Skip to content

fixed structure bug!#230

Merged
Jakeroid merged 7 commits into
gruns:masterfrom
MarkLevkovich:structure-fix
Jan 12, 2026
Merged

fixed structure bug!#230
Jakeroid merged 7 commits into
gruns:masterfrom
MarkLevkovich:structure-fix

Conversation

@MarkLevkovich

@MarkLevkovich MarkLevkovich commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Fix confusing list order display for medium-sized lists
Problem
When using ic() with medium-sized lists (13-35 elements), pprint.pformat breaks them into one element per line due to width constraints (~80 chars). This creates visual confusion where the list order appears to be reversed or scrambled, even though the actual data order is correct.
Example of the problem:
ic([1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,0,1,0,1,0])
Would display as:
ic| [0,
1,
0,
1,
0,
1,
0,
1,
...]
Solution
Modified safe_pformat() in icecream/icecream.py to:

  1. First try formatting with increased width (120 chars) for lists

  2. If the list still breaks into multiple lines but meets specific criteria:

    • 13-35 elements (problematic range for default pprint)
    • Overall length < 120 characters (fits reasonably on one line)
    • Broken into >10 lines (indicates one-per-line formatting)
    • No nested lists (avoid breaking multiline expressions)

    Then fall back to repr() for clean single-line display.
    Changes

  • Updated safe_pformat() function with intelligent list formatting logic
  • Targets only the problematic case that causes user confusion
  • Preserves existing behavior for nested lists and very large lists
    Testing
  • ✅ Fixes the reported bug - medium lists now display on one line
  • ✅ 40/41 existing tests pass
  • ❌ 1 test (testMultilineContainerArgs) expects old multiline behavior for nested lists
    The failing test expects multiline display for lists within multiline expressions, which is a separate concern from the reported bug. The current implementation provides better UX for the common case while preserving multiline formatting for complex expressions.

@MarkLevkovich MarkLevkovich reopened this Jan 6, 2026
@Jakeroid

Jakeroid commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator

@MarkLevkovich Thank you very much for this. I'm checking it.

@Jakeroid

Jakeroid commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator

@MarkLevkovich I have some feedback. You PR have changed a lot of formatting. For instance there are:

  • single quotes changed to double quotes
  • some lines become multiple lines and vise versa

Could you please remove unnecessary changes and provide only the fix?

@MarkLevkovich

Copy link
Copy Markdown
Contributor Author

Sorry my first PR, now I'll fix everything

@Jakeroid

Jakeroid commented Jan 7, 2026

Copy link
Copy Markdown
Collaborator

@MarkLevkovich don't worry

thank you

@Jakeroid Jakeroid mentioned this pull request Jan 12, 2026
@Jakeroid

Copy link
Copy Markdown
Collaborator

@MarkLevkovich

There is an issue with the test test_multiline_container_args

======================================================================
ERROR: tests.test_install (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_install
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/runner/work/icecream/icecream/tests/test_install.py", line 16, in <module>
    from tests.test_icecream import (
  File "/home/runner/work/icecream/icecream/tests/test_icecream.py", line 574
    def test_multiline_container_args(self):
    ^
IndentationError: expected an indented block

@MarkLevkovich

Copy link
Copy Markdown
Contributor Author

mb now

@Jakeroid Jakeroid merged commit 099f763 into gruns:master Jan 12, 2026
8 checks passed
@Jakeroid

Copy link
Copy Markdown
Collaborator

@MarkLevkovich Good job!

I'll take a look on fresh head tomorrow and probably make a new release.

@Jakeroid Jakeroid mentioned this pull request Jan 12, 2026
@MarkLevkovich

Copy link
Copy Markdown
Contributor Author

@Jakeroid thanks for your time

@MarkLevkovich MarkLevkovich deleted the structure-fix branch January 12, 2026 19:31
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.

2 participants