From f09d7c720b860ed0e18a8afc058fc49f1bcff8e4 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Fri, 13 Feb 2026 13:06:20 -0800 Subject: [PATCH 1/2] Register imported CLI sub-namespaces in sys.modules --- src/core/IronPython/Runtime/Importer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/IronPython/Runtime/Importer.cs b/src/core/IronPython/Runtime/Importer.cs index 6f3db9812..42d81b6a2 100644 --- a/src/core/IronPython/Runtime/Importer.cs +++ b/src/core/IronPython/Runtime/Importer.cs @@ -127,7 +127,11 @@ private static object ImportModuleFrom(CodeContext/*!*/ context, object from, Ar string name = parts.Array[parts.Offset + parts.Count - 1]; if (from is NamespaceTracker ns) { if (ns.TryGetValue(name, out object val)) { - return MemberTrackerToPython(context, val); + object ret = MemberTrackerToPython(context, val); + if (ret != null && val is NamespaceTracker retns && !context.LanguageContext.SystemStateModules.ContainsKey(retns.Name)) { + context.LanguageContext.SystemStateModules[retns.Name] = ret; + } + return ret; } } From 2d322371916589358145986682e232b8f0336330 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Fri, 13 Feb 2026 13:17:46 -0800 Subject: [PATCH 2/2] Add tests --- tests/suite/test_cliclass.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/suite/test_cliclass.py b/tests/suite/test_cliclass.py index 8b6bbafc8..28c1e2a8c 100644 --- a/tests/suite/test_cliclass.py +++ b/tests/suite/test_cliclass.py @@ -1199,11 +1199,14 @@ def test_serialization(self): System.StringSplitOptions.RemoveEmptyEntries, ] - if False: - # TODO: Enum types are not picklable if defined in nested namespaces - # https://github.com/IronLanguages/ironpython3/issues/1989 - clr.AddReference("System.Text.Json") - data.append(System.Text.Json.JsonValueKind.Object) # byte-based enum + if is_cli: + # enum types + clr.AddReference("Microsoft.Scripting") + import Microsoft.Scripting + data.append(Microsoft.Scripting.Severity.Warning) # different namespace than System + if is_netcoreapp: + clr.AddReference("System.Text.Json") + data.append(System.Text.Json.JsonValueKind.Object) # byte-based enum data.append(list(data)) # list of all the data.. data.append(tuple(data)) # tuple of all the data...