Repository navigation
Conversation
BCSharp
reviewed
Oct 28, 2026
BCSharp
left a comment
Member
There was a problem hiding this comment.
I see that this is work in progress, but here are my findings so far after playing with it for a while.
| // anything unusual goes through _gcd_import for its errors | ||
| try { | ||
| module = PythonOps.Invoke(context, bootstrap, "_gcd_import", absName); | ||
| } catch (ImportException e) when (level == 0 && !modName.Contains('.') |
Member
There was a problem hiding this comment.
Consider this:
>>> import clr
>>> g = clr.GetCurrentRuntime().Globals
>>> import sys
>>> sys.modules['blocked_name'] = None
>>> import blocked_name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2222, in _gcd_import
ImportError: import of blocked_name halted; None in sys.modules
>>> g.blocked_name = 42
>>> import blocked_name
>>> sys.modules['blocked_name']
42Looks like a regression. ImportError is expected in both cases.
Comment on lines
+358
to
+363
| int firstDot = modName.IndexOf('.'); | ||
| int cutOff = firstDot == -1 ? 0 : modName.Length - firstDot; | ||
| string topName = absName.Substring(0, absName.Length - cutOff); | ||
| if (!modules.TryGetValue(topName, out top)) { | ||
| throw PythonOps.KeyError($"{PythonOps.Repr(context, topName)} not in sys.modules as expected"); | ||
| } |
Member
There was a problem hiding this comment.
# assume packages p, p.a, p.a.b already exist
import p.a.b
import sys
sys.modules['p.a'] = None
__import__("a.b", {"__package__": "p"}, None, None, 1)
# CPython: None (value of sys.modules['p.a'])
# IronPython: ImportError: No module named 'a.b'Perhaps setting top = module when firstDot == -1?
slozier
marked this pull request as draft
October 29, 2026 03:44
Contributor
Author
|
Ran into a complication for which I'm undecided. Using |
slozier
marked this pull request as ready for review
October 30, 2026 00:12
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.
Use
importlibfor__import__. Includes fast paths written in C# so performance should be similar to what we had before. The legacy mechanism is still available with the (debug-only)-X NoImportLiboption.Breaking changes:
PalImporterto re-enable this as a follow-up PR)importlib.invalidate_caches()is called, like CPythonimportlib._bootstrap, custom importers now follow CPython semantics (find_specis preferred overfind_module, etc.)ImportErrorifsitecan't be found (use-Sto skip)Follow up items:
ImportModuleWithImportLib:ShowClsat the import statement, like__future__clr.AddReferenceoutside of__import__