Skip to content

Commit 3beb5e9

Browse files
committed
fix issue #124442: make __static_attributes__ deterministic by sorting
Signed-off-by: kp2pml30 <[email protected]>
1 parent 54dd77f commit 3beb5e9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Make `compile` builtin function deterministic by sorting
2+
`__static_attributes__` before dumping to the bytecode #.. section: Library
3+
#.. section: Documentation #.. section: Tests #.. section: Build #..
4+
section: Windows #.. section: macOS #.. section: IDLE #.. section:
5+
Tools/Demos #.. section: C API
6+
7+
# Write your Misc/NEWS.d entry below. It should be a simple ReST paragraph.
8+
# Don't start with "- Issue #<n>: " or "- gh-issue-<n>: " or that sort of
9+
stuff.
10+
###########################################################################

Python/compile.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,14 @@ PyObject *
911911
_PyCompile_StaticAttributesAsTuple(compiler *c)
912912
{
913913
assert(c->u->u_static_attributes);
914-
return PySequence_Tuple(c->u->u_static_attributes);
914+
PyObject *static_attributes_unsorted = PySequence_List(c->u->u_static_attributes);
915+
if (static_attributes_unsorted == NULL) {
916+
return NULL;
917+
}
918+
PyList_Sort(static_attributes_unsorted);
919+
PyObject *static_attributes = PySequence_Tuple(static_attributes_unsorted);
920+
Py_DECREF(static_attributes_unsorted);
921+
return static_attributes;
915922
}
916923

917924
int

0 commit comments

Comments
 (0)