Skip to content

gh-102799: Let pydoc use the exception instead of sys.exc_info - #102830

Merged
iritkatriel merged 2 commits into
python:mainfrom
iritkatriel:pydoc
Mar 21, 2023
Merged

gh-102799: Let pydoc use the exception instead of sys.exc_info#102830
iritkatriel merged 2 commits into
python:mainfrom
iritkatriel:pydoc

Conversation

@iritkatriel

@iritkatrieliritkatriel commented Mar 19, 2023

Copy link
Copy Markdown
Member

@terryjreedyterryjreedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Except for suggestions, looks good. I satisfied my question.

Comment threadLib/pydoc.py Outdated
Comment on lines 392 to 396
if not isinstance(exc_info, tuple):
assert isinstance(exc_info, BaseException)
exc_info = type(exc_info), exc_info, exc_info.__traceback__
self.filename = filename
self.exc, self.value, self.tb = exc_info

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Separate suggestions:

  1. Keep handling of two args in order. First first and second second. Handling first in middle of second is unnecessary confusion.
  2. Handle two cases of second separately. Don't create tuple just to unpack. Unpacking makes it slightly more obvious that same attributes are defined, but pack/unpack makes it harder to see what object is assigned to each attribute.
Suggested change
ifnotisinstance(exc_info, tuple):
assertisinstance(exc_info, BaseException)
exc_info=type(exc_info), exc_info, exc_info.__traceback__
self.filename=filename
self.exc, self.value, self.tb=exc_info
self.filename=filename
ifisinstance(exc_info, tuple):
self.exc, self.value, self.tb=exc_info
else:
assertisinstance(exc_info, BaseException)
self.exc=type(exc_info)
self.value=exc_info
self.tb=exc_info.__traceback__

I am tempted to think that no user will ever raise this exception. pydoc is only documented as a command-line app, not as importable library. But this is not idlelib. Can/should we emit a DeprecationWarning in the isinstance clause? It could then be removed someday. Since there is no doc of the module content, no changed notice is needed.

Comment threadLib/pydoc.py Outdated
del sys.modules[key]
module = __import__(path)
except:
except BaseException as e:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I personally prefer 'err' to 'e'. I have no idea of any general consensus.

Comment threadLib/pydoc.py
@iritkatrieliritkatriel changed the title gh-102799: pydoc doesn't need to use sys.exc_infogh-102799: Let pydoc use the exception instead of sys.exc_infoMar 21, 2023
@iritkatriel
iritkatriel merged commit 868490e into python:mainMar 21, 2023
@iritkatriel
iritkatriel deleted the pydoc branch April 3, 2023 17:42
donbarbos added a commit to donbarbos/typeshed that referenced this pull request Jan 10, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@iritkatriel@terryjreedy@bedevere-bot