STINNER Victor <[email protected]> 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 <[email protected]>
<https://bugs.python.org/issue42955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com