mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[3.13] gh-124442: make __static_attributes__
deterministic by sorting (GH-124492) (#124738)
* [3.13] gh-124442: make `__static_attributes__` deterministic by sorting (GH-124492)
(cherry picked from commit 04c837d9d8
)
Co-authored-by: Kira <kp2pml30@gmail.com>
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>
This commit is contained in:
parent
b843974ab4
commit
b99c6620b2
3 changed files with 31 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import contextlib
|
||||
import dis
|
||||
import io
|
||||
import itertools
|
||||
import math
|
||||
import opcode
|
||||
import os
|
||||
|
@ -2619,6 +2620,22 @@ class TestInstructionSequence(unittest.TestCase):
|
|||
self.compare_instructions(seq, [('LOAD_CONST', 1, 1, 0, 0, 0)])
|
||||
self.compare_instructions(seq.get_nested()[0], [('LOAD_CONST', 2, 2, 0, 0, 0)])
|
||||
|
||||
def test_static_attributes_are_sorted(self):
|
||||
code = (
|
||||
'class T:\n'
|
||||
' def __init__(self):\n'
|
||||
' self.{V1} = 10\n'
|
||||
' self.{V2} = 10\n'
|
||||
' def foo(self):\n'
|
||||
' self.{V3} = 10\n'
|
||||
)
|
||||
attributes = ("a", "b", "c")
|
||||
for perm in itertools.permutations(attributes):
|
||||
var_names = {f'V{i + 1}': name for i, name in enumerate(perm)}
|
||||
ns = run_code(code.format(**var_names))
|
||||
t = ns['T']
|
||||
self.assertEqual(t.__static_attributes__, attributes)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue