On Mon, Jan 25, 2021 at 6:37 PM Chris Jerdonek <[email protected]> wrote: > On Mon, Jan 25, 2021 at 7:51 AM Ivan Pozdeev via Python-Dev > <[email protected]> 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... > > Would another use case be to support issuing a warning if a third-party > module is imported whose name matches a standard one? A related use case > would be to build on this and define a function that accepts an already > imported module and return whether it is from the standard library. Unlike, > the module_names attribute, this function would reflect the reality of the > underlying module, and so not have false positives as with doing a name check > alone.
This is a different use case which requires a different solution. sys.module_names solve some specific use cases (that I listed in my first email). In Python 3.9, you can already check if a module __file__ is in the sysconfig.get_paths()['stdlib'] directory. You don't need to modify Python for that. If you also would like to check if an *extension* module comes from the stdlib, you need to get the "lib-dynload" directory. I failed to find a programmatic way to get this directory, maybe new API would be needed for that. Victor -- Night gathers, and now my watch begins. It shall not end until my death. _______________________________________________ Python-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/4BTCHRA4XUWXHXHDGXSRJSH6LFS66TF5/ Code of Conduct: http://python.org/psf/codeofconduct/
