diff options
author | Kira <kp2pml30@gmail.com> | 2024-09-28 22:15:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-28 22:15:43 (GMT) |
commit | 04c837d9d8a474777ef9c1412fbba14f0682366c (patch) | |
tree | f15aa115d8380ceea4f3b5f6f722751f0676bf8a /Python | |
parent | 69a4063ca516360b5eb96f5432ad9f9dfc32a72e (diff) | |
download | cpython-04c837d9d8a474777ef9c1412fbba14f0682366c.zip cpython-04c837d9d8a474777ef9c1412fbba14f0682366c.tar.gz cpython-04c837d9d8a474777ef9c1412fbba14f0682366c.tar.bz2 |
gh-124442: make `__static_attributes__` deterministic by sorting (#124492)
Signed-off-by: kp2pml30 <kp2pml30@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c index 7b3e6f3..9826d3f 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -911,7 +911,17 @@ PyObject * _PyCompile_StaticAttributesAsTuple(compiler *c) { assert(c->u->u_static_attributes); - return PySequence_Tuple(c->u->u_static_attributes); + PyObject *static_attributes_unsorted = PySequence_List(c->u->u_static_attributes); + if (static_attributes_unsorted == NULL) { + return NULL; + } + if (PyList_Sort(static_attributes_unsorted) != 0) { + Py_DECREF(static_attributes_unsorted); + return NULL; + } + PyObject *static_attributes = PySequence_Tuple(static_attributes_unsorted); + Py_DECREF(static_attributes_unsorted); + return static_attributes; } int |