-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Implement importlib.abc.InspectLoader in AssertionRewritingHook #7885
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
base: main
Are you sure you want to change the base?
Implement importlib.abc.InspectLoader in AssertionRewritingHook #7885
Conversation
IMHO it is easier to just implement |
I'm pretty sure that subclassing FileLoader and SourceLoader would require splitting the loader functionality from the rewriting hook. That wouldn't be too hard, but wouldn't buy much and requires more code. |
Something else: I'm not sure what's the best way to add tests for the new methods. I'm not a pytest user myself. |
Returns the code for a rewritten test file. | ||
""" | ||
# The type annotation is *Optional[...]* to match the declaration | ||
# in importlib.abc.InspectLoader |
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.
this comment is unnecessary -- the type checker will enforce this for us (remove the other one as well)
try: | ||
fn = Path(self._fullname_to_info[fullname][0]) | ||
except KeyError: | ||
raise ImportError(fullname) |
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.
is this error possible? this shouldn't be needed in a PEP451 loader (the code retrieval step doesn't happen if the finder isn't returned) -- this makes me think that we've reverted back to 302
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.
yeah InspectLoader is the 302 interface which would regress us back into imp
land
This is a first take at a PR for issue #7804, at this time without tests and documentation updates.
At this time I'm primarily interested to hear if the code changes are acceptable.
closes #7804.
Here is a quick checklist that should be present in PRs.
If this change fixes an issue, please:
closes #XYZW
to the PR description and/or commits (whereXYZW
is the issue number). See the github docs for more information.Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please:
Create a new changelog file in the
changelog
folder, with a name like<ISSUE NUMBER>.<TYPE>.rst
. See changelog/README.rst for details.Write sentences in the past or present tense, examples:
Also make sure to end the sentence with a
.
.Add yourself to
AUTHORS
in alphabetical order.