_stdlib.py 552 B

1234567891011121314151617181920
  1. # mypy: allow-untyped-defs
  2. """List of Python standard library modules.
  3. Sadly, there is no reliable way to tell whether a module is part of the
  4. standard library except by comparing to a canonical list.
  5. This is taken from https://github.com/PyCQA/isort/tree/develop/isort/stdlibs,
  6. which itself is sourced from the Python documentation.
  7. """
  8. import sys
  9. def is_stdlib_module(module: str) -> bool:
  10. base_module = module.partition(".")[0]
  11. return base_module in _get_stdlib_modules()
  12. def _get_stdlib_modules():
  13. return sys.stdlib_module_names