@@ -860,30 +860,37 @@ def test_subinterp_intern_singleton(self):
860860 ''' ))
861861 self .assertTrue (sys ._is_interned (s ))
862862
863- def test_sys_flags (self ):
863+ def test_sys_flags_indexable_attributes (self ):
864864 self .assertTrue (sys .flags )
865- attrs = ("debug" ,
865+ # We've stopped assigning sequence indices to new sys.flags attributes:
866+ # https://github.com/python/cpython/issues/122575#issuecomment-2416497086
867+ indexable_attrs = ("debug" ,
866868 "inspect" , "interactive" , "optimize" ,
867869 "dont_write_bytecode" , "no_user_site" , "no_site" ,
868870 "ignore_environment" , "verbose" , "bytes_warning" , "quiet" ,
869871 "hash_randomization" , "isolated" , "dev_mode" , "utf8_mode" ,
870- "warn_default_encoding" , "safe_path" , "int_max_str_digits" ,
871- "lazy_imports" , "traceback_timestamps" )
872- for attr in attrs :
872+ "warn_default_encoding" , "safe_path" , "int_max_str_digits" )
873+ for attr_idx , attr in enumerate (indexable_attrs ):
873874 self .assertHasAttr (sys .flags , attr )
874875 attr_type = bool if attr in ("dev_mode" , "safe_path" ) else int
875876 attr_type = str if attr == "traceback_timestamps" else attr_type
876877 self .assertEqual (type (getattr (sys .flags , attr )), attr_type , attr )
878+ attr_value = getattr (sys .flags , attr )
879+ self .assertEqual (sys .flags [attr_idx ], attr_value ,
880+ msg = f"sys.flags .{ attr } vs [{ attr_idx } ]" )
877881 self .assertTrue (repr (sys .flags ))
878- self .assertEqual (len (sys .flags ), 18 ) # Do not increase, see GH-122575
882+ self .assertEqual (len (sys .flags ), 18 , msg = " Do not increase, see GH-122575" )
879883
880884 self .assertIn (sys .flags .utf8_mode , {0 , 1 , 2 })
881885
882- # non-tuple sequence fields
886+ def test_sys_flags_name_only_attributes (self ):
887+ # non-tuple sequence fields (name only sys.flags attributes)
883888 self .assertIsInstance (sys .flags .gil , int | type (None ))
889+ self .assertIsInstance (sys .flags .thread_inherit_context , int | type (None ))
890+ self .assertIsInstance (sys .flags .context_aware_warnings , int | type (None ))
891+ self .assertIsInstance (sys .flags .lazy_imports , int | type (None ))
884892 self .assertIsInstance (sys .flags .traceback_timestamps , str )
885893
886-
887894 def assert_raise_on_new_sys_type (self , sys_attr ):
888895 # Users are intentionally prevented from creating new instances of
889896 # sys.flags, sys.version_info, and sys.getwindowsversion.
@@ -1923,7 +1930,9 @@ def test_pythontypes(self):
19231930 # - 'context_aware_warnings'
19241931 # - 'lazy_imports'
19251932 # - 'traceback_timestamps'
1926- # It will not be necessary once GH-122575 is fixed.
1933+ # Not needing to increment this every time we add a new field
1934+ # per GH-122575 would be nice...
1935+ # Q: What is the actual point of this sys.flags C size derived from PyStructSequence_Field array assertion?
19271936 non_sequence_fields = 5
19281937 check (sys .flags , vsize ('' ) + self .P + self .P * (non_sequence_fields + len (sys .flags )))
19291938
0 commit comments