Skip to content

PYTHONINSPECT is checked inconsistently #143135

Closed

Description

@StanFromIreland

Found when testing PYTHONINSPECT for #143134, when you set PYTHONINSPECT to a "non-empty" string that is 0, it is checked in initconfig.c with _Py_get_env_flag:

_Py_get_env_flag(use_env, &config->inspect, "PYTHONINSPECT");

But then directly with _Py_GetEnv in pymain_repl:

cpython/Modules/main.c

Lines 579 to 581 in fc2f0fe

if (!config->inspect && _Py_GetEnv(config->use_environment, "PYTHONINSPECT")) {
pymain_set_inspect(config, 1);
}

So, you end up in this situation:

$ PYTHONINSPECT=0 ./python -c "import sys; print(sys.flags.inspect)"
0
>>> # We still inspect, even though sys.flags.inspect is not set...

Linked PRs

Activity

  1. added
    type-bug
    interpreter-core
    on Dec 24, 2025
  2. serhiy-storchaka commented on Dec 24, 2025

    @serhiy-storchaka
    Member

    According to documentation:

       If this is set to a non-empty string it is equivalent to specifying the
       :option:`-i` option.

    So, sys.flags.inspect is incorrect.

  3. StanFromIreland commented on Dec 24, 2025

    @StanFromIreland
    MemberAuthor

    So you prefer to fix them all: #143134?

  4. serhiy-storchaka commented on Dec 24, 2025

    @serhiy-storchaka
    Member

    No, in other cases the documentation is wrong. But in this case it seems that only the value of sys.flags.inspect is incorrect. The interpreter behavior and the documentation are consistent.

  5. added a commit that references this issue on Dec 24, 2025
  6. added a commit that references this issue on Dec 24, 2025
  7. added a commit that references this issue on Dec 24, 2025
  8. added a commit that references this issue on Dec 25, 2025
  9. added a commit that references this issue on Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-coretype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions