You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

typing.py 1.1KB

1234567891011121314151617181920212223242526272829
  1. """For neatly implementing static typing in pip.
  2. `mypy` - the static type analysis tool we use - uses the `typing` module, which
  3. provides core functionality fundamental to mypy's functioning.
  4. Generally, `typing` would be imported at runtime and used in that fashion -
  5. it acts as a no-op at runtime and does not have any run-time overhead by
  6. design.
  7. As it turns out, `typing` is not vendorable - it uses separate sources for
  8. Python 2/Python 3. Thus, this codebase can not expect it to be present.
  9. To work around this, mypy allows the typing import to be behind a False-y
  10. optional to prevent it from running at runtime and type-comments can be used
  11. to remove the need for the types to be accessible directly during runtime.
  12. This module provides the False-y guard in a nicely named fashion so that a
  13. curious maintainer can reach here to read this.
  14. In pip, all static-typing related imports should be guarded as follows:
  15. from pip.utils.typing import MYPY_CHECK_RUNNING
  16. if MYPY_CHECK_RUNNING:
  17. from typing import ...
  18. Ref: https://github.com/python/mypy/issues/3216
  19. """
  20. MYPY_CHECK_RUNNING = False