From 4a1674a148c50c5d02a38611deb5416e732912d7 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Tue, 22 Dec 2015 15:37:03 -0800 Subject: [PATCH] Improve Python 2 stub for abc; _weakrefset stub. --- builtins/2.7/_weakrefset.pyi | 5 +++++ stdlib/2.7/abc.pyi | 41 ++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 builtins/2.7/_weakrefset.pyi diff --git a/builtins/2.7/_weakrefset.pyi b/builtins/2.7/_weakrefset.pyi new file mode 100644 index 000000000..a3de693e6 --- /dev/null +++ b/builtins/2.7/_weakrefset.pyi @@ -0,0 +1,5 @@ +from typing import Iterator, Any + +class WeakSet: + def __iter__(self) -> Iterator[Any]: ... + def add(self, *args, **kwargs) -> Any: ... diff --git a/stdlib/2.7/abc.pyi b/stdlib/2.7/abc.pyi index 675f0b162..9cc5620a4 100644 --- a/stdlib/2.7/abc.pyi +++ b/stdlib/2.7/abc.pyi @@ -1,5 +1,38 @@ -# Stubs for abc. +from typing import Any, Dict, Set, Union, Tuple +import _weakrefset -# Thesee definitions have special processing in type checker. -class ABCMeta: ... -abstractmethod = object() +# mypy has special processing for ABCMeta and abstractmethod. + +WeakSet = ... # type: _weakrefset.WeakSet +_InstanceType = ... # type: type +types = ... # type: module + +def abstractmethod(funcobj) -> Any: ... + +class ABCMeta(type): + # TODO: FrozenSet + __abstractmethods__ = ... # type: Set[Any] + __doc__ = ... # type: str + _abc_cache = ... # type: _weakrefset.WeakSet + _abc_invalidation_counter = ... # type: int + _abc_negative_cache = ... # type: _weakrefset.WeakSet + _abc_negative_cache_version = ... # type: int + _abc_registry = ... # type: _weakrefset.WeakSet + def __init__(self, name, bases, namespace: Dict[Any, Any]) -> None: ... + def __instancecheck__(cls: "ABCMeta", instance) -> Any: ... + def __subclasscheck__(cls: "ABCMeta", subclass) -> Any: ... + def _dump_registry(cls: "ABCMeta", *args, **kwargs) -> None: ... + # TODO: subclass: Union["ABCMeta", type, Tuple[type, ...]] + def register(cls: "ABCMeta", subclass: Any) -> None: ... + +class _C: + pass + +# TODO: The real abc.abstractproperty inherits from "property". +class abstractproperty(object): + __doc__ = ... # type: str + __isabstractmethod__ = ... # type: bool + doc = ... # type: Any + fdel = ... # type: Any + fget = ... # type: Any + fset = ... # type: Any