brain_datetime.py 813 B

1234567891011121314151617181920
  1. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  2. # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
  3. # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
  4. from astroid import nodes
  5. from astroid.brain.helpers import register_module_extender
  6. from astroid.builder import AstroidBuilder
  7. from astroid.const import PY312_PLUS
  8. from astroid.manager import AstroidManager
  9. def datetime_transform() -> nodes.Module:
  10. """The datetime module was C-accelerated in Python 3.12, so use the
  11. Python source."""
  12. return AstroidBuilder(AstroidManager()).string_build("from _pydatetime import *")
  13. def register(manager: AstroidManager) -> None:
  14. if PY312_PLUS:
  15. register_module_extender(manager, "datetime", datetime_transform)