Skip to content

Fix: changed size during iteration when pretty-printing dicts and sets - #15469

Open
nikhil822 wants to merge 1 commit into
ipython:mainfrom
nikhil822:fix/runtime-error-posix
Open

nikhil822 wants to merge 1 commit into
ipython:mainfrom
nikhil822:fix/runtime-error-posix

Conversation

@nikhil822

Copy link
Copy Markdown

Fixes #14541

The dict and set printers looped over the live container while printing each
item. Printing an item can change the container: for vars(posix), printing
posix.chmod calls inspect.signature(), which runs eval(..., posix.__dict__),
and eval adds __builtins__ to that dict. Sets with at least max_seq_length
items are not sorted first, so they had the same problem
(Set changed size during iteration).

RepresentationPrinter._enumerate now loops over a copy of at most
max_seq_length + 1 items, which fixes both printers and avoids copying the
whole of a large dict that will be cut off anyway.

This branch has not been deployed

No deployments
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.

RuntimeError on first call to vars(posix)

1 participant