If the length of the name is any kind of issue, since the stdlib only contains modules (and packages), why not just sys.stdlib_names?


On Mon, Jan 25, 2021 at 5:18 PM Victor Stinner <vstinner@python.org> wrote:
Hi Bernat,

"stdlib_module_names" was my first idea but it looks too long, so I
chose "module_names". But someone on Twitter and now you asked me why
not "stdlib_module_names", so I wrote a PR to rename module_names to
sys.stdlib_module_names:
https://github.com/python/cpython/pull/24332

At least "stdlib_module_names" better summarizes its definition: "A
frozenset of strings containing the names of standard library
modules".

Victor


On Mon, Jan 25, 2021 at 5:39 PM Bernat Gabor <jokerjokerer@gmail.com> wrote:
>
> Hello,
>
> In general, I love the idea and implementation. I'm not in love with the name though, it makes it sound like it contains all module names imported/available. We have sys.module already containing all module imported. So without a deeper knowledge sys.modules_names is very close to sys.module.keys() or all available modules. Can we name it instead sys.stdlib_modules_names to clarify that this is standard library only subset and not all available modules for the interpreter?
>
> Thanks,
>
> On Mon, Jan 25, 2021 at 4:33 PM Victor Stinner <vstinner@python.org> wrote:
>>
>> Hi Ivan,
>>
>> On Mon, Jan 25, 2021 at 4:53 PM Ivan Pozdeev via Python-Dev
>> <python-dev@python.org> wrote:
>> > Just _names_? There's a recurring error case when a 3rd-party module overrides a standard one if it happens to have the same name. If you
>> > filter such a module out, you're shooting yourself in the foot...
>>
>> Overriding stdlib modules has been discussed in the issue.
>>
>> For example, it was proposed to add an attribute to all stdlib modules
>> (__stdlib__=True or __author__ = 'PSF'), and then check if the
>> attribute exists or not. The problem is that importing a module to
>> check for its attribute cause side effect or fail, and so cannot be
>> used for some use cases. For example, it would be a surprising to open
>> a web browser window when running isort on a Python code containing
>> "import antigravity". Another problem is that third party can also add
>> the attribute to pretend that their code is part of the stdlib.
>>
>> In a previous version of my PR, I added a note about sys.path and
>> overriding stdlib modules, but I have been asked to remove it. Feel
>> free to propose a PR to add such note if you consider that it's
>> related to sys.module_names.
>>
>> Please read the discussion at https://bugs.python.org/issue42955 and
>> https://github.com/python/cpython/pull/24238
>>
>> Victor
>> _______________________________________________
>> Python-Dev mailing list -- python-dev@python.org
>> To unsubscribe send an email to python-dev-leave@python.org
>> https://mail.python.org/mailman3/lists/python-dev.python.org/
>> Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/7HMWTGBECAVLINLO3MAEN74YVDHOMZKM/
>> Code of Conduct: http://python.org/psf/codeofconduct/



--
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/WJMYK2JKZPTXMID7WRMP4KMJ656WEMI5/
Code of Conduct: http://python.org/psf/codeofconduct/