__init__.py 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. # This is a stub package designed to roughly emulate the _yaml
  2. # extension module, which previously existed as a standalone module
  3. # and has been moved into the `yaml` package namespace.
  4. # It does not perfectly mimic its old counterpart, but should get
  5. # close enough for anyone who's relying on it even when they shouldn't.
  6. import yaml
  7. # in some circumstances, the yaml module we imoprted may be from a different version, so we need
  8. # to tread carefully when poking at it here (it may not have the attributes we expect)
  9. if not getattr(yaml, '__with_libyaml__', False):
  10. from sys import version_info
  11. exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError
  12. raise exc("No module named '_yaml'")
  13. else:
  14. from yaml._yaml import *
  15. import warnings
  16. warnings.warn(
  17. 'The _yaml extension module is now located at yaml._yaml'
  18. ' and its location is subject to change. To use the'
  19. ' LibYAML-based parser and emitter, import from `yaml`:'
  20. ' `from yaml import CLoader as Loader, CDumper as Dumper`.',
  21. DeprecationWarning
  22. )
  23. del warnings
  24. # Don't `del yaml` here because yaml is actually an existing
  25. # namespace member of _yaml.
  26. __name__ = '_yaml'
  27. # If the module is top-level (i.e. not a part of any specific package)
  28. # then the attribute should be set to ''.
  29. # https://docs.python.org/3.8/library/types.html
  30. __package__ = ''