gh-125519: Improve traceback if importlib.reload() is called with a non-module object#125520
Merged
AlexWaygood merged 1 commit intopython:mainfrom Oct 21, 2024
Merged
Conversation
…with a non-module object
AlexWaygood
commented
Oct 15, 2024
Comment on lines
+358
to
+370
| def test_reload_traceback_with_non_str(self): | ||
| # gh-125519 | ||
| with support.captured_stdout() as stdout: | ||
| try: | ||
| self.init.reload("typing") | ||
| except TypeError as exc: | ||
| traceback.print_exception(exc, file=stdout) | ||
| else: | ||
| self.fail("Expected TypeError to be raised") | ||
| printed_traceback = stdout.getvalue() | ||
| self.assertIn("TypeError", printed_traceback) | ||
| self.assertNotIn("AttributeError", printed_traceback) | ||
| self.assertNotIn("module.__spec__.name", printed_traceback) |
Member
Author
There was a problem hiding this comment.
We could also do this with assertions on the __cause__ or __context__ attribute of the raised exception, but that feels like asserting an implementation detail to me. I prefer for the test to assert what the user will be seeing when the exception is raised (which feels like the important thing).
hauntsaninja
approved these changes
Oct 21, 2024
|
Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Oct 21, 2024
…with a non-module object (pythonGH-125520) (cherry picked from commit c5c21fe) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Oct 21, 2024
…with a non-module object (pythonGH-125520) (cherry picked from commit c5c21fe) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
|
GH-125768 is a backport of this pull request to the 3.13 branch. |
|
GH-125769 is a backport of this pull request to the 3.12 branch. |
Member
Author
|
Thanks for the review @hauntsaninja! |
ebonnal
pushed a commit
to ebonnal/cpython
that referenced
this pull request
Jan 12, 2025
…with a non-module object (python#125520)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
importlib.reload()is called with astr#125519