[Python-Dev] PEP 432 progress: Python initalization

Victor Stinner victor.stinner at gmail.com
Thu Dec 14 17:25:39 EST 2017


2017-12-14 22:54 GMT+01:00 Terry Reedy <tjreedy at udel.edu>:
> You could have (and still could) made that a master issue with multiple
> dependencies.  Last summer, I merged at least 20 patches for one idlelib
> file.  I split them up among 1 master issue and about 6 dependency issues.
> That was essential because most of the patches were written by one of 3 new
> contributors and needed separate discussions about the strategy for a
> particular patch.
>
> I completely agree with keeping PRs to a reviewable size.

I'm not sure that multiple issues are needed since all these changes
are related to Py_Main() or are very close to Py_Main(), and they
implement what is defined in the PEP 432.

Technically, I could push a single giant commit, but it would be
impossible to review it, even for myself, whereas I'm reading each
change multiple times. I'm testing each change on Windows, macOS,
Linux and FreeBSD to make sure that everything is fine. Py_Main() has
a few functions specific to one platform like Windows or macOS. I also
had to "iterate" on the code to move slowly the code, step by step.

I'm not really proud of all these refactoring changes :-( But I hope
that "at the end", the code will be much easier to understand and to
maintain.

Moreover, as I wrote, my intent is also to fix all the code handling
configuration.

For example, I just fixed the code to define sys.argv earlier. Now,
sys.argv is defined very soon in Python initialization. Previously,
sys.argv was only defined after Py_Initialize() completed. For
example, the site module cannot access sys.argv:

Traceback (most recent call last):
  File "/home/vstinner/prog/python/3.6/Lib/site.py", line 600, in <module>
    print(sys.argv)
AttributeError: module 'sys' has no attribute 'argv'

I'm not sure that it's useful, but I was surprised that sys was only
partially initialized before the site moduel was loaded.

Victor


More information about the Python-Dev mailing list