Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP-654: add example of subgroup callback with side effects #1852

Merged
merged 5 commits into from
Mar 1, 2021

Conversation

iritkatriel
Copy link
Member

No description provided.


.. code-block::

def leaf_generator(exc, tbs=None):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could show a little code fragment that uses this as well? It would have to include at least

try:
    . . .
except *OSError as eg:
    for exc, tbs in leaf_generator(eg):
        if exc.errno != ENOENT:
            print(exc)
            <show how to print the traceback using the traceback module>

I think the last line would have to call extract_tb() for each item of tbs, concatenate the lists (in which order?), and then call print_list() on the concatenation. I'm too lazy to research how exactly.

pep-0654.rst Outdated Show resolved Hide resolved
pep-0654.rst Outdated Show resolved Hide resolved
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Strange, the two minor fixups I applied came back. Also, there are two spaces missing from the output. Is the code correct?

Otherwise LG.

pep-0654.rst Outdated Show resolved Hide resolved
pep-0654.rst Outdated Show resolved Hide resolved
pep-0654.rst Outdated
File "<stdin>", line 3, in g
ValueError: 1
The complete traceback for Exception #1
File "<stdin>", line 2, in <module>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
File "<stdin>", line 2, in <module>
File "<stdin>", line 2, in <module>

Copy link
Member Author

Choose a reason for hiding this comment

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

let me check this

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah the code gives it indented. I messed it up in the copy-paste.

iritkatriel and others added 3 commits March 1, 2021 23:19
Co-authored-by: Guido van Rossum <[email protected]>
Co-authored-by: Guido van Rossum <[email protected]>
Co-authored-by: Guido van Rossum <[email protected]>
@gvanrossum gvanrossum merged commit 274670b into python:master Mar 1, 2021
... eg = e
...
>>> for (i, (exc, tbs)) in enumerate(leaf_generator(eg)):
... print(f"\n>>> Exception #{i+1}:")
Copy link
Member Author

@iritkatriel iritkatriel Mar 1, 2021

Choose a reason for hiding this comment

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

">>>" was a poor choice here, it gets mixed up with the interactive prompt. I'll replace it.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I already merged. Awaiting your next PR...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants