-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# test overriding __import__ combined with importing from the filesystem | ||
|
||
|
||
def custom_import(name, globals, locals, fromlist, level): | ||
print("import", name, fromlist, level) | ||
return orig_import(name, globals, locals, fromlist, level) | ||
|
||
|
||
orig_import = __import__ | ||
try: | ||
__import__("builtins").__import__ = custom_import | ||
except AttributeError: | ||
print("SKIP") | ||
raise SystemExit | ||
|
||
# import calls __import__ behind the scenes | ||
import pkg7.subpkg1.subpkg2.mod3 | ||
|
||
|
||
try: | ||
# globals must be a dict or None, not a string | ||
orig_import("builtins", "globals", None, None, 0) | ||
except TypeError: | ||
print("TypeError") | ||
try: | ||
# ... same for relative imports (level > 0) | ||
orig_import("builtins", "globals", None, None, 1) | ||
except TypeError: | ||
print("TypeError") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pkg7.subpkg1.subpkg2.mod3 None 0 | ||
pkg __name__: pkg7 | ||
pkg __name__: pkg7.subpkg1 | ||
pkg __name__: pkg7.subpkg1.subpkg2 | ||
import ('mod1',) 3 | ||
import pkg7.mod1 True 0 | ||
mod1 | ||
import mod2 ('bar',) 3 | ||
mod2 | ||
mod1.foo | ||
mod2.bar | ||
import ('mod1',) 4 | ||
ImportError | ||
TypeError | ||
TypeError |
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.
py/builtinimport: support relative import in custom __import__ callbacks #6665
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: master
Are you sure you want to change the base?
py/builtinimport: support relative import in custom __import__ callbacks #6665
Changes from all commits
483b2e9
823eefb
3bf3066
0109a24
bd1e1e7
3ae7d8e
81c9376
8413c46
e2640ea
f416bd8
765a494
70ef973
16df159
483b91e
4a36076
e73ff98
209981c
2c19cd5
87e6387
ff58f5a
721bd30
b4a2153
db57e34
5585562
0579aba
600ca07
d978379
4e16027
f64b34f
bab170b
2aaacbd
5143d37
3a46dc0
9a08ff6
cc31c03
File filter
8000Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.