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
Leverage importlib.reload
for reloading modules
#11679
Merged
AA-Turner
merged 8 commits into
sphinx-doc:master
from
godlygeek:leverage_importlib_reload
Sep 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c727fcc
Leverage `importlib.reload` for reloading modules
godlygeek ca51520
Merge branch 'master' into leverage_importlib_reload
AA-Turner e909d52
Add escape hatch
AA-Turner 159ac90
Cython
AA-Turner 98c53e0
KeyError
AA-Turner 5320222
Merge branch 'master' into leverage_importlib_reload
AA-Turner 6fb5d9c
CHANGES
AA-Turner ec974cd
Swap
AA-Turner File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Oops, something went wrong.
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.
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.
Can we have a narrower exception type than Exception?
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 don't think so -- at least, not without sacrificing correctness. If I change this to just catch
ImportError
, then doing:fails with::
Let me flip the question around on you: given that the module was already imported successfully with
typing.TYPE_CHECKING == False
, which sorts of exceptions encountered while reloading the module withtyping.TYPE_CHECKING == True
should causeimport_object
to fail instead of using the already successfully imported module?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.
Good point. I take it from your testing that e.g. if
pydantic
is successfully imported, and then fails on the reload, the initial imported module is still usable, coherent, etc?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.
That's my expectation, and it seems to be the case for pydantic, at least up to the point where a basic
.. automodule:: pydantic
succeeds. I'm not sure how to test it more thoroughly, though. I do suspect that this is still going to be fragile in ways that we can't predict, the hope is just that it works for more cases than both what's in #11511 and what's in #11645