Attempt to reduce cyclical dependencies between types and importlib. (#335)

- Move Loader and ModuleType into _importlib_modulespec.pyi.
- Add "import X as X" for these to types.pyi and importlib/abc.pyi.

The goal is to ensure mypy -i still works, to fix https://github.com/python/mypy/issues/1797.
This commit is contained in:
Guido van Rossum
2016-07-05 10:23:24 -07:00
committed by GitHub
parent 8fb9f4a8f1
commit 8515cf5de8
5 changed files with 55 additions and 47 deletions

View File

@@ -3,8 +3,6 @@
# TODO parts of this should be conditional on version
import importlib.abc
from importlib._modulespec import ModuleSpec
import sys
from typing import (
Any, Callable, Dict, Generic, Iterator, Mapping, Optional, Tuple, TypeVar,
@@ -108,17 +106,9 @@ class BuiltinFunctionType:
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
BuiltinMethodType = BuiltinFunctionType
class ModuleType:
__name__ = ... # type: str
__file__ = ... # type: str
__doc__ = ... # type: Optional[str]
if sys.version_info >= (3, 4):
__loader__ = ... # type: Optional[importlib.abc.Loader]
__package__ = ... # type: Optional[str]
# Should be Optional[ModuleSpec], but importlib.machinery has no stub
# yet.
__spec__ = ... # type: Optional[ModuleSpec]
def __init__(self, name: str, doc: str) -> None: ...
# ModuleType is exported from this module, but for circular import
# reasons exists in its own stub file (with ModuleSpec and Loader).
from _importlib_modulespec import ModuleType as ModuleType # Exported
class TracebackType:
tb_frame = ... # type: FrameType