Skip to content

pprint - low width overrides depth folding #89774

Open

Description

@iansedano
mannequin
BPO 45611
Nosy @iansedano

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2021-10-26.07:40:20.607>
labels = ['type-bug', 'library', '3.10']
title = 'pprint - low width overrides depth folding'
updated_at = <Date 2021-10-26.07:40:20.607>
user = 'https://github.com/iansedano'

bugs.python.org fields:

activity = <Date 2021-10-26.07:40:20.607>
actor = 'iansedano'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2021-10-26.07:40:20.607>
creator = 'iansedano'
dependencies = []
files = []
hgrepos = []
issue_num = 45611
keywords = []
message_count = 1.0
messages = ['405027']
nosy_count = 1.0
nosy_names = ['iansedano']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue45611'
versions = ['Python 3.10']

Linked PRs

Activity

  1. iansedano commented on Oct 26, 2021

    iansedanomannequin
    MannequinAuthor

    Reproducible example:

    >>> from pprint import pprint
    >>> data = [["aaaaaaaaaaaaaaaaaa"],[2],[3],[4],[5]]
    >>> pprint(data)
    [["aaaaaaaaaaaaaaaaaa"], [2], [3], [4], [5]]
    
    >>> pprint(data, depth=1)
    [[...], [...], [...], [...], [...]]
    
    >>> pprint(data, depth=1, width=7)
    [[...],
     [...],
     [...],
     [...],
     [...]]
    
    >>> pprint(data, depth=1, width=6)
    [['aaaaaaaaaaaaaaaaaa'],
     [2],
     [3],
     [4],
     [5]]

    The depth "folds" everything deeper than 1 level. Then if you lower the width of the output enough, what was once on one line, will now be split by newlines.

    The bug is, if you lower the width below seven characters. Which is the length of [[...], It seems to override the depth parameter and print the everything with no folding. This is true of deeply nested structures too.

    Expected behavior: for the folding ... to remain.

    Why put the width so low?

    I came across this because of the behavior of compact:

    By default, if a data structure can fit on one line, it will be displayed on one line. compact only affects sequences that are longer than the given width.

    **There is no way to force compact as False for short items**, so as to make sure all items, even short ones, appear on their own line.

    [1,2,3] - will always appear on its own line, there is no way to make it appear like:

    [1,
    2,
    3]

    The only way is by setting a very low width.

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Oct 26, 2021
  3. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions