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

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

Merged
merged 2 commits into from
Mar 21, 2023

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Mar 19, 2023

Copy link
Member

@terryjreedy terryjreedy left a comment

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.

Lib/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
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
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
self.filename = filename
if isinstance(exc_info, tuple):
self.exc, self.value, self.tb = exc_info
else:
assert isinstance(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.

Lib/pydoc.py Outdated
@@ -440,21 +443,20 @@ def safeimport(path, forceload=0, cache={}):
cache[key] = sys.modules[key]
del sys.modules[key]
module = __import__(path)
except:
except BaseException as e:
Copy link
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.

@iritkatriel iritkatriel changed the title gh-102799: pydoc doesn't need to use sys.exc_info gh-102799: Let pydoc use the exception instead of sys.exc_info Mar 21, 2023
@iritkatriel iritkatriel merged commit 868490e into python:main Mar 21, 2023
@iritkatriel iritkatriel deleted the pydoc branch April 3, 2023 17:42
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