py3k_compat.py 645 B

1234567891011121314151617181920212223242526272829303132333435
  1. import sys
  2. from collections.abc import Callable
  3. from typing import Any, Dict, Optional
  4. is_ironpython = "IronPython" in sys.version
  5. def is_callable(x: Any) -> bool:
  6. return isinstance(x, Callable)
  7. def execfile(
  8. fname: str,
  9. glob: Dict[str, Any],
  10. loc: Optional[Dict[str, Any]] = None,
  11. ) -> None:
  12. loc = loc if (loc is not None) else glob
  13. with open(
  14. fname,
  15. "r",
  16. encoding="utf-8",
  17. ) as file:
  18. file_contents = file.read()
  19. # pylint: disable=W0122
  20. exec(
  21. compile(
  22. file_contents,
  23. fname,
  24. "exec",
  25. ),
  26. glob,
  27. loc,
  28. )