Skip to content

Commit a26fd29

Browse files
d-torrancemikestillman
authored andcommitted
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 python/cpython#99541.
1 parent 7a9c1cc commit a26fd29

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

M2/Macaulay2/d/python.d

+2-2
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ setupfun("pythonWrapM2Function", PyWrapM2Function);
430430
-- none --
431431
----------
432432

433-
PyNone(e:Expr):Expr := toExpr(Ccode(pythonObjectOrNull, "Py_None"));
434-
setupfun("getPythonNone", PyNone);
433+
setupconst("pythonNone",
434+
Expr(pythonObjectCell(Ccode(pythonObject, "Py_None"), 0xFCA86420)));
435435

436436
---------------
437437
-- importing --

M2/Macaulay2/packages/Python.m2

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ exportFrom_Core {
6969
"objectType"}
7070

7171
importFrom_Core {
72-
"getPythonNone",
7372
"pythonComplexFromDoubles",
7473
"pythonDictNew",
7574
"pythonDictSetItem",
@@ -81,6 +80,7 @@ importFrom_Core {
8180
"pythonLongFromLong",
8281
"pythonFloatAsDouble",
8382
"pythonFloatFromDouble",
83+
"pythonNone",
8484
"pythonObjectGetAttrString",
8585
"pythonObjectHasAttrString",
8686
"pythonObjectRichCompareBool",
@@ -120,8 +120,6 @@ PythonObject#AfterPrint = x -> (
120120
t = replace("<([a-z]+) '(.*)'>"," of \\1 \\2",t);
121121
(PythonObject, t))
122122

123-
pythonNone = getPythonNone()
124-
125123
pythonValue = method(Dispatch => Thing)
126124
pythonValue String := s -> (
127125
if debugLevel > 0 then printerr("python command: ", s);

0 commit comments

Comments
 (0)