Mailing List Archive

1 2  View All
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:

Another use case similar to the "isort" use case: vim plugin to insert an import, it checks if the module name is a stdlib module. It checks the module path (for Python stdlib modules) and uses an hardcoded list of builtin stdlib modules.

https://github.com/mgedmin/python-imports.vim

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:

Another example: the unimport project ("linter, formatter for finding and removing unused import statements") uses the following function to guess if a module object is part of the stdlib:

def is_std(package: str) -> bool:
"""Returns True if package module came with from Python."""

if package in C.BUILTIN_MODULE_NAMES:
return True
spec = get_spec(package)
if spec and isinstance(spec.origin, str):
return any(
(
spec.origin.startswith(C.STDLIB_PATH),
spec.origin in ["built-in", "frozen"],
spec.origin.endswith(".so"),
)
)
else:
return False

https://github.com/hakancelik96/unimport/blob/c9bd5de99bd8a5239d3dee2c3ff633979bb3ead2/unimport/utils.py#L61-L77

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
SylvainDe <sylvain.desodt@gmail.com> added the comment:

For similar reasons as friendly-traceback, I'd be interested in a list of stdlib modules to be able to provide additional information in case of exceptions.

For instance:

string.ascii_lowercase
> Before: NameError("name 'string' is not defined",)
> After: NameError("name 'string' is not defined. Did you mean to import string first)

from maths import pi
> Before: ImportError('No module named maths',)
> After: ImportError("No module named maths. Did you mean 'math'?",)

choice
> Before: NameError("name 'choice' is not defined",)
> After: NameError("name 'choice' is not defined. Did you mean 'choice' from random (not imported)?",)

from itertools import pi
> Before: ImportError('cannot import name pi',)
> After: ImportError("cannot import name pi. Did you mean 'from math import pi'?",)

The first 2 cases only use the module name but the last 2 cases will actually import the modules to get the names in it and I want to do this for modules which are safe to import (no side-effect expected).

Source: https://github.com/SylvainDe/DidYouMean-Python/blob/master/didyoumean/didyoumean_internal.py#L30 (but if you are interested in that kind of features, I'd recommend using friendly-traceback instead)

----------
nosy: +SylvainDe

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
Change by hai shi <shihai1991@126.com>:


----------
nosy: +shihai1991

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:

Another potential use case: restrict pydoc web server to stdlib modules, see bpo-42988.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
Change by Andre Roberge <andre.roberge@gmail.com>:


----------
nosy: +aroberge

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:


New changeset db584bdad32d81e42b71871077a8008036f5c048 by Victor Stinner in branch 'master':
bpo-42955: Add sys.modules_names (GH-24238)
https://github.com/python/cpython/commit/db584bdad32d81e42b71871077a8008036f5c048


----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:

I merged my PR, thanks for the feedback and reviews.

----------
resolution: -> fixed
stage: patch review -> resolved
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
Change by STINNER Victor <vstinner@python.org>:


----------
pull_requests: +23148
pull_request: https://github.com/python/cpython/pull/24329

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:


New changeset 483359174e92489e13959977824806734f1a8cdd by Victor Stinner in branch 'master':
bpo-42955: Fix sys.module_names doc (GH-24329)
https://github.com/python/cpython/commit/483359174e92489e13959977824806734f1a8cdd


----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
Change by STINNER Victor <vstinner@python.org>:


----------
pull_requests: +23151
pull_request: https://github.com/python/cpython/pull/24332

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules) [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:


New changeset 9852cb38112a4f8d11e26c3423643ea994d5a14f by Victor Stinner in branch 'master':
bpo-42955: Rename module_names to sys.stdlib_module_names (GH-24332)
https://github.com/python/cpython/commit/9852cb38112a4f8d11e26c3423643ea994d5a14f


----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

1 2  View All