From a26fd29829c14529cf28edaee813616b1162cce3 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Mon, 26 Jun 2023 10:24:50 -0400 Subject: [PATCH] Use constant hash for Python's "None" object This way, we don't need the "getPythonNone" function, which was only called once, to create the object. Beginning with Python 3.12, None will have a constant hash anyway. We use this new value. See https://github.com/python/cpython/pull/99541. --- M2/Macaulay2/d/python.d | 4 ++-- M2/Macaulay2/packages/Python.m2 | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/M2/Macaulay2/d/python.d b/M2/Macaulay2/d/python.d index 18b08f7a7c3..e3e772614dd 100644 --- a/M2/Macaulay2/d/python.d +++ b/M2/Macaulay2/d/python.d @@ -430,8 +430,8 @@ setupfun("pythonWrapM2Function", PyWrapM2Function); -- none -- ---------- -PyNone(e:Expr):Expr := toExpr(Ccode(pythonObjectOrNull, "Py_None")); -setupfun("getPythonNone", PyNone); +setupconst("pythonNone", + Expr(pythonObjectCell(Ccode(pythonObject, "Py_None"), 0xFCA86420))); --------------- -- importing -- diff --git a/M2/Macaulay2/packages/Python.m2 b/M2/Macaulay2/packages/Python.m2 index ede6db2e03d..67bc3976cf5 100644 --- a/M2/Macaulay2/packages/Python.m2 +++ b/M2/Macaulay2/packages/Python.m2 @@ -69,7 +69,6 @@ exportFrom_Core { "objectType"} importFrom_Core { - "getPythonNone", "pythonComplexFromDoubles", "pythonDictNew", "pythonDictSetItem", @@ -81,6 +80,7 @@ importFrom_Core { "pythonLongFromLong", "pythonFloatAsDouble", "pythonFloatFromDouble", + "pythonNone", "pythonObjectGetAttrString", "pythonObjectHasAttrString", "pythonObjectRichCompareBool", @@ -120,8 +120,6 @@ PythonObject#AfterPrint = x -> ( t = replace("<([a-z]+) '(.*)'>"," of \\1 \\2",t); (PythonObject, t)) -pythonNone = getPythonNone() - pythonValue = method(Dispatch => Thing) pythonValue String := s -> ( if debugLevel > 0 then printerr("python command: ", s);