Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lib/pickletools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2539,8 +2539,6 @@ def dis(pickle, out=None, memo=None, indentlevel=4, annotate=0):
stack.extend(after)

print("highest protocol among opcodes =", maxproto, file=out)
if stack:
raise ValueError("stack not empty after STOP: %r" % stack)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if removing the exception makes sense or not. But if we decide to change the code, I would prefer to keep the information: maybe replace raise ValueError() with print().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that exception is raised after printing all output. You do not lose any information. You can catch and ignore this exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so we're not worried about this then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can catch and ignore this exception.

It's not easy when using pickletools CLI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using CLI you get some output. Whether it a Python traceback or a single line, -- it does not matter much, since such case is exceptional. The CLI output is not formalized, anything is fine.

We could add a mechanism for outputting non-critical errors, but since this particular error is raised after finishing all output, it would not make much difference.


# For use in the doctest, simply as an example of a class to pickle.
class _Example:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`pickletools` no longer errors out when more than one item is left in the stack upon reaching the `STOP` opcode
Loading