You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sys.flags.gil should be a "sequence" attribute OR stop adding to the sequence #122575
Generally, changing n_in_sequence is a backwards-incompatible change: code that unpacks the tuple will break.
With 18 elements, and after int_max_str_digits was added in a bugfix release, I guess no one unpacks sys.flags specifically.
Still, it might be better to change PyStructSequence.__repr__ than to allow sys.flags[18]?
Generally, changing n_in_sequence is a backwards-incompatible change...
That seems like an entirely hypothetical concern. As you wrote, I don't think anyone unpacks the 18 or 19 elements of sys.flags. The longstanding practice is to include added elements. The last time this we did this was when we added int_max_str_digits in 3.12, which not only was included as a positional element, but backported all the way back to 3.7:
This is the only PyStructSequence that has a non-sequence element, and the omission was an oversight, not intentional.
Still, it might be better to change PyStructSequence.__repr__
I don't think so. These are publicly documented as "named tuples" and named tuples do not support this feature of attributes that are only accessible by name.
Here's what I think. Perhaps this needs wider discussion.
This is the only PyStructSequence that has a non-sequence element
That's not the case:
>>> import os
>>> os.stat('.').n_fields
19
>>> os.stat('.').n_sequence_fields
10
The last time this we did this was when we added int_max_str_digits in 3.12, which not only was included as a positional element, but backported all the way back to 3.7
Sadly, yes. The security fix didn't go through public review.
As far as I can tell, the next-to-last time we did this was in 2019. In my view, both of those were oversights.
I don't think so. These are publicly documented as "named tuples" and named tuples do not support this feature of attributes that are only accessible by name.
Note that the whole concept name-only attributes was added to PyStructSequence specifically in order to not break unpacking, back when PyStructSequence was added to replace real tuples: #35189 (comment)
(If it wasn't for backwards compatibility with older tuple API, structseqs would probably just be “structs”; not iterable at all.)
Sadly, the user-facing documentation for creating these types doesn't mention how they should be used in stdlib.
Generally, changing n_in_sequence is a backwards-incompatible change: code that unpacks the tuple will break.
Over the last years, many flags were added to sys.flags and I don't recall a single bug report.
I'm convinced that nobody is unpacking sys.flags. It sounds boring to write flag1, flag2, flag3, ..., flag18 = sys.flags, while you can just write value = sys.flags[12].
I'm locking down the sequence length for sys.flags in #145988 - new attributes are now name only. the lazy imports addition PR accidentally incremented the sequence length (exposing sys.flags.gil as [18], not exposing any of the other 3 fields added after that), the PR undoes that and updates tests and code comments to make it clear that we don't want new indices.
changed the title [-]`sys.flags.gil` should be a "sequence" attribute[/-][+]`sys.flags.gil` should be a "sequence" attribute OR stop adding to the sequence[/+]on Mar 15, 2026
Activity
pythongh-122575: Include `sys.flags.gil` as a sequence attribute
encukou commentedon Aug 2, 2024
Generally, changing
n_in_sequenceis a backwards-incompatible change: code that unpacks the tuple will break.With 18 elements, and after
int_max_str_digitswas added in a bugfix release, I guess no one unpackssys.flagsspecifically.Still, it might be better to change
PyStructSequence.__repr__than to allowsys.flags[18]?colesbury commentedon Aug 2, 2024
That seems like an entirely hypothetical concern. As you wrote, I don't think anyone unpacks the 18 or 19 elements of
sys.flags. The longstanding practice is to include added elements. The last time this we did this was when we addedint_max_str_digitsin 3.12, which not only was included as a positional element, but backported all the way back to 3.7:This is the only
PyStructSequencethat has a non-sequence element, and the omission was an oversight, not intentional.I don't think so. These are publicly documented as "named tuples" and named tuples do not support this feature of attributes that are only accessible by name.
encukou commentedon Aug 2, 2024
Here's what I think. Perhaps this needs wider discussion.
That's not the case:
Sadly, yes. The security fix didn't go through public review.
As far as I can tell, the next-to-last time we did this was in 2019. In my view, both of those were oversights.
Note that the whole concept name-only attributes was added to
PyStructSequencespecifically in order to not break unpacking, back whenPyStructSequencewas added to replace real tuples: #35189 (comment)(If it wasn't for backwards compatibility with older tuple API, structseqs would probably just be “structs”; not iterable at all.)
Sadly, the user-facing documentation for creating these types doesn't mention how they should be used in stdlib.
colesbury commentedon Aug 2, 2024
Thanks, I misinterpreted what I saw in gh-122577 and missed that.
We've added flags over a dozen times before that. Every time we've updated
n_in_sequenceor fixed it up in a subsequent commit (e.g., 90e8f8c)If you want to implement this differently, that's fine with me, but I think it's a waste of time.
vstinner commentedon Sep 2, 2024
Over the last years, many flags were added to sys.flags and I don't recall a single bug report.
I'm convinced that nobody is unpacking
sys.flags. It sounds boring to writeflag1, flag2, flag3, ..., flag18 = sys.flags, while you can just writevalue = sys.flags[12].encukou commentedon Oct 16, 2024
Unfortunately I haven't had time to dig deeper. Don't take my concern too seriously.
vstinner commentedon Oct 16, 2024
Python 3.13.0 is now shipped without
sys.flags[18]. IMO it's now too late to change it.vstinner commentedon Oct 16, 2024
IMO we should deprecate the tuple API for
sys.flags. It sounds really bad to rely on an exact flag "index" to get a flag, instead of using its name.Good example:
Bad example:
pythongh-122575: pythongh-142349: fix sys.flags tuple size (it uninte…
gpshead commentedon Mar 15, 2026
I'm locking down the sequence length for sys.flags in #145988 - new attributes are now name only. the lazy imports addition PR accidentally incremented the sequence length (exposing sys.flags.gil as [18], not exposing any of the other 3 fields added after that), the PR undoes that and updates tests and code comments to make it clear that we don't want new indices.
gh-122575: gh-142349: fix sys.flags tuple size (it unintentionally in…
[-]`sys.flags.gil` should be a "sequence" attribute[/-][+]`sys.flags.gil` should be a "sequence" attribute OR stop adding to the sequence[/+]pythongh-122575: pythongh-142349: fix sys.flags tuple size (it uninte…