Skip to content

Commit

Permalink
Use constant hash for Python's "None" object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
d-torrance committed Aug 30, 2023
1 parent 609eec6 commit 6cb3b7c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions M2/Macaulay2/d/python.d
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down
4 changes: 1 addition & 3 deletions M2/Macaulay2/packages/Python.m2
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ exportFrom_Core {
"objectType"}

importFrom_Core {
"getPythonNone",
"pythonComplexFromDoubles",
"pythonDictNew",
"pythonDictSetItem",
Expand All @@ -81,6 +80,7 @@ importFrom_Core {
"pythonLongFromLong",
"pythonFloatAsDouble",
"pythonFloatFromDouble",
"pythonNone",
"pythonObjectGetAttrString",
"pythonObjectHasAttrString",
"pythonObjectRichCompareBool",
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6cb3b7c

Please sign in to comment.