-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
Conversation
iritkatriel
commented
Mar 19, 2023
•
edited by bedevere-bot
Loading
edited by bedevere-bot
- Issue: some usages of sys.exc_info can be replaced by more modern code #102799
There was a problem hiding this 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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate suggestions:
- Keep handling of two args in order. First first and second second. Handling first in middle of second is unnecessary confusion.
- 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.
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: |
There was a problem hiding this comment.
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.