mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
Finish implementation of the types module
Note that many classes will need special handling in the typing module.
This commit is contained in:
@@ -1,16 +1,26 @@
|
||||
# Stubs for types
|
||||
# Note, all classes "defined" here require special handling.
|
||||
|
||||
# TODO this is work in progress
|
||||
# TODO parts of this should be conditional on version
|
||||
|
||||
from typing import Any, Callable, Dict, Sequence, Optional, Tuple
|
||||
from typing import Any, Callable, Dict, Iterator, Optional, Tuple, TypeVar, Union, overload
|
||||
|
||||
class ModuleType:
|
||||
__name__ = ... # type: str
|
||||
__file__ = ... # type: str
|
||||
def __init__(self, name: str, doc: Any) -> None: ...
|
||||
_T = TypeVar('_T')
|
||||
|
||||
class MethodType: ...
|
||||
class BuiltinMethodType: ...
|
||||
class _Cell:
|
||||
cell_contents = ... # type: Any
|
||||
|
||||
class FunctionType:
|
||||
__closure__ = ... # type: Optional[Tuple[_Cell, ...]]
|
||||
__code__ = ... # type: CodeType
|
||||
__defaults__ = ... # type: Optional[Tuple[Any, ...]]
|
||||
__dict__ = ... # type: Dict[str, Any]
|
||||
__doc__ = ... # type: Optional[str]
|
||||
__globals__ = ... # type: Dict[str, Any]
|
||||
__name__ = ... # type: str
|
||||
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
||||
def __get__(self, obj: Optional[object], type: Optional[type]) -> 'MethodType': ...
|
||||
LambdaType = FunctionType
|
||||
|
||||
class CodeType:
|
||||
"""Create a code object. Not for the faint of heart."""
|
||||
@@ -47,6 +57,64 @@ class CodeType:
|
||||
cellvars: Tuple[str, ...] = (),
|
||||
) -> None: ...
|
||||
|
||||
class MappingProxyType:
|
||||
def copy(self) -> dict: ...
|
||||
def get(self, key: str, default: _T = None) -> Union[Any, _T]: ...
|
||||
def items(self) -> Iterator[Tuple[str, Any]]: ...
|
||||
def keys(self) -> Iterator[str]: ...
|
||||
def values(self) -> Iterator[Any]: ...
|
||||
def __contains__(self, key: str) -> bool: ...
|
||||
def __getitem__(self, key: str) -> Any: ...
|
||||
def __iter__(self) -> Iterator[str]: ...
|
||||
def __len__(self) -> int: ...
|
||||
class SimpleNamespace: ...
|
||||
|
||||
class GeneratorType:
|
||||
gi_code = ... # type: CodeType
|
||||
gi_frame = ... # type: FrameType
|
||||
gi_running = ... # type: bool
|
||||
gi_yieldfrom = ... # type: Optional[GeneratorType]
|
||||
def __iter__(self) -> 'GeneratorType': ...
|
||||
def __next__(self) -> Any: ...
|
||||
def close(self) -> None: ...
|
||||
def send(self, arg: Any) -> Any: ...
|
||||
@overload
|
||||
def throw(self, val: BaseException) -> Any: ...
|
||||
@overload
|
||||
def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ...
|
||||
|
||||
class CoroutineType:
|
||||
cr_await = ... # type: Optional[Any]
|
||||
cr_code = ... # type: CodeType
|
||||
cr_frame = ... # type: FrameType
|
||||
cr_running = ... # type: bool
|
||||
def close(self) -> None: ...
|
||||
def send(self, arg: Any) -> Any: ...
|
||||
@overload
|
||||
def throw(self, val: BaseException) -> Any: ...
|
||||
@overload
|
||||
def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ...
|
||||
|
||||
class MethodType:
|
||||
__func__ = ... # type: FunctionType
|
||||
__self__ = ... # type: object
|
||||
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
||||
class BuiltinFunctionType:
|
||||
__self__ = ... # type: Union[object, ModuleType]
|
||||
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
||||
BuiltinMethodType = BuiltinFunctionType
|
||||
|
||||
class ModuleType:
|
||||
__name__ = ... # type: str
|
||||
__file__ = ... # type: str
|
||||
def __init__(self, name: str, doc: Any) -> None: ...
|
||||
|
||||
class TracebackType:
|
||||
tb_frame = ... # type: FrameType
|
||||
tb_lasti = ... # type: int
|
||||
tb_lineno = ... # type: int
|
||||
tb_next = ... # type: TracebackType
|
||||
|
||||
class FrameType:
|
||||
f_back = ... # type: FrameType
|
||||
f_builtins = ... # type: Dict[str, Any]
|
||||
@@ -59,8 +127,23 @@ class FrameType:
|
||||
|
||||
def clear(self) -> None: pass
|
||||
|
||||
class TracebackType:
|
||||
tb_frame = ... # type: FrameType
|
||||
tb_lasti = ... # type: int
|
||||
tb_lineno = ... # type: int
|
||||
tb_next = ... # type: TracebackType
|
||||
class GetSetDescriptorType:
|
||||
__name__ = ... # type: str
|
||||
__objclass__ = ... # type: type
|
||||
def __get__(self, obj: Any, type: type = None) -> Any: ...
|
||||
def __set__(self, obj: Any) -> None: ...
|
||||
def __delete__(self, obj: Any) -> None: ...
|
||||
class MemberDescriptorType:
|
||||
__name__ = ... # type: str
|
||||
__objclass__ = ... # type: type
|
||||
def __get__(self, obj: Any, type: type = None) -> Any: ...
|
||||
def __set__(self, obj: Any) -> None: ...
|
||||
def __delete__(self, obj: Any) -> None: ...
|
||||
|
||||
def new_class(name: str, bases: Tuple[type, ...] = (), kwds: Dict[str, Any] = None, exec_body: Callable[[Dict[str, Any]], None] = None) -> type: ...
|
||||
def prepare_class(name: str, bases: Tuple[type, ...] = (), kwds: Dict[str, Any] = None) -> Tuple[type, Dict[str, Any], Dict[str, Any]]: ...
|
||||
|
||||
# Actually a different type, but `property` is special and we want that too.
|
||||
DynamicClassAttribute = property
|
||||
|
||||
def coroutine(f: Callable[..., Any]) -> CoroutineType: ...
|
||||
|
||||
Reference in New Issue
Block a user