◐ Shell
clean mode source ↗

gh-122575: Include `sys.flags.gil` as a sequence attribute by colesbury · Pull Request #122576 · python/cpython

Make sure that `sys.flags.gil` is included when `sys.flags` is treated
as a tuple or named tuple.

@colesbury colesbury marked this pull request as ready for review

August 1, 2024 20:10

@colesbury

picnixz

* - .. attribute:: flags.warn_default_encoding
- :option:`-X warn_default_encoding <-X>`

* - .. attribute:: flags.gil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should explain that the gil takes values 0, 1, or 2 and possibly explain the corresponding values (or a link to them) (and also say that None means the free-threaded build (if I'm not wrong)).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the right place for that, is it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually I don't really know where it would be the right place... I just wanted to point it out since a new variable is being documented (I don't know whether there already exists another place so feel free to ignore this comment!)

attr_types = {
"dev_mode": bool,
"safe_path": bool,
"gil": (int, type(None)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the None value mean that it's the free-threaded build or is it for something else?

@AA-Turner

Potentially,

 .. data:: flags
    The :term:`named tuple` *flags* exposes the status of command line
    flags. The attributes are read only.
+   The number of flags may change in any version of Python,
+   do not unpack ``sys.flags`` or index into it as a tuple.

which would document that we change sys.flags with some regularity.

A

ericsnowcurrently

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

vstinner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if you apply the Py_ARRAY_LENGTH() suggestion.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

@vstinner

Ah, you should now update test_pythontypes() of test_sys.

@colesbury