Skip to content

Commit 4cfbe5f

Browse files
authored
Add PythonContext.GetCopyRegModule (#965)
1 parent 91bde90 commit 4cfbe5f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Src/IronPython.Modules/re.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public static class PythonRegex {
3535
[SpecialName]
3636
public static void PerformModuleReload(PythonContext/*!*/ context, PythonDictionary/*!*/ dict) {
3737
context.EnsureModuleException("reerror", dict, "error", "re");
38-
PythonCopyReg.GetDispatchTable(context.SharedContext)[DynamicHelpers.GetPythonTypeFromType(typeof(Pattern))] = dict["_pickle"];
38+
var module = context.GetCopyRegModule();
39+
if (module != null) {
40+
var pickle = PythonOps.GetBoundAttr(context.SharedContext, module, "pickle");
41+
PythonOps.CallWithContext(context.SharedContext, pickle, DynamicHelpers.GetPythonTypeFromType(typeof(Pattern)), dict["_pickle"]);
42+
}
3943
}
4044

4145
private static readonly Random r = new Random(DateTime.Now.Millisecond);

Src/IronPython/Runtime/PythonContext.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,15 @@ internal PythonModule GetReloadableModule(PythonModule/*!*/ module) {
11111111

11121112
#endregion
11131113

1114+
private object copyRegModule;
1115+
1116+
internal object GetCopyRegModule() {
1117+
if (copyRegModule is null) {
1118+
copyRegModule = Importer.ImportModule(SharedContext, new PythonDictionary(), "copyreg", false, 0);
1119+
}
1120+
return copyRegModule;
1121+
}
1122+
11141123
public object GetWarningsModule() {
11151124
object warnings = null;
11161125
try {

0 commit comments

Comments
 (0)