From 2beebffcdbbbad20a265e9730c71ef8fa5fd1a2f Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Sat, 28 Jan 2017 01:05:33 +0300 Subject: [PATCH 1/4] Corrected special attributes present in object or its direct inheritors object itself doesn't have __dict__ and __slots__, but all its inheritors do have either __dict__ or __slots__. --- stdlib/2/__builtin__.pyi | 6 ++++-- stdlib/3/builtins.pyi | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 6b1d178742e5..f5c9cad900f3 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -30,13 +30,13 @@ class classmethod: pass # Special, only valid as a decorator. class object: __doc__ = ... # type: Optional[str] __class__ = ... # type: type + __dict__ = ... # type: Dict[Union[str, unicode], Any] __slots__ = ... # type: Optional[Union[str, unicode, Iterable[Union[str, unicode]]]] + __module__ = ... # type: Any def __init__(self) -> None: ... def __new__(cls) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... - def __eq__(self, o: object) -> bool: ... - def __ne__(self, o: object) -> bool: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... def __hash__(self) -> int: ... @@ -44,6 +44,8 @@ class object: def __getattribute__(self, name: str) -> Any: ... def __delattr__(self, name: str) -> None: ... def __sizeof__(self) -> int: ... + def __reduce__(self) -> Union[str, unicode, tuple]: ... + def __reduce_ex__(self, protocol: int) -> Union[str, unicode, tuple]: ... class type(object): __bases__ = ... # type: Tuple[type, ...] diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 7811b228c557..167229a34018 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -34,12 +34,11 @@ class object: __class__ = ... # type: type __dict__ = ... # type: Dict[str, Any] __slots__ = ... # type: Optional[Union[str, Iterable[str]]] + __module__ = ... # type: Any def __init__(self) -> None: ... def __new__(cls) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... - def __eq__(self, o: object) -> bool: ... - def __ne__(self, o: object) -> bool: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... def __hash__(self) -> int: ... @@ -47,6 +46,8 @@ class object: def __getattribute__(self, name: str) -> Any: ... def __delattr__(self, name: str) -> None: ... def __sizeof__(self) -> int: ... + def __reduce__(self) -> Union[str, tuple]: ... + def __reduce_ex__(self, protocol: int) -> Union[str, tuple]: ... if sys.version_info >= (3, 6): def __init_subclass__(cls) -> None: ... From 75149475efd92a38a37fcfc75f103aad559813ea Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Sat, 28 Jan 2017 01:21:44 +0300 Subject: [PATCH 2/4] Use plain 'str' as type of keys in __dict__ similar to other special attributes --- stdlib/2/__builtin__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index f5c9cad900f3..f5a1f3b1406a 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -30,7 +30,7 @@ class classmethod: pass # Special, only valid as a decorator. class object: __doc__ = ... # type: Optional[str] __class__ = ... # type: type - __dict__ = ... # type: Dict[Union[str, unicode], Any] + __dict__ = ... # type: Dict[str, Any] __slots__ = ... # type: Optional[Union[str, unicode, Iterable[Union[str, unicode]]]] __module__ = ... # type: Any From 3c3b4027b16da503035993eaacc68e6120026fa0 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Sat, 28 Jan 2017 01:30:14 +0300 Subject: [PATCH 3/4] Removed overridden __dict__ and added object as base class --- stdlib/2/__builtin__.pyi | 6 ++---- stdlib/2/types.pyi | 3 +-- stdlib/3/builtins.pyi | 4 +--- stdlib/3/types.pyi | 1 - 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index f5a1f3b1406a..de68294fb71c 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -51,7 +51,6 @@ class type(object): __bases__ = ... # type: Tuple[type, ...] __name__ = ... # type: str __module__ = ... # type: str - __dict__ = ... # type: Dict[unicode, Any] @overload def __init__(self, o: object) -> None: ... @@ -655,12 +654,11 @@ class xrange(Sized, Iterable[int], Reversible[int]): def __getitem__(self, i: int) -> int: ... def __reversed__(self) -> Iterator[int]: ... -class module: +class module(object): __name__ = ... # type: str __file__ = ... # type: str - __dict__ = ... # type: Dict[unicode, Any] -class property: +class property(object): def __init__(self, fget: Callable[[Any], Any] = None, fset: Callable[[Any, Any], None] = None, fdel: Callable[[Any], None] = None, doc: str = None) -> None: ... diff --git a/stdlib/2/types.pyi b/stdlib/2/types.pyi index 2f3b93549205..d325a202e502 100644 --- a/stdlib/2/types.pyi +++ b/stdlib/2/types.pyi @@ -28,7 +28,7 @@ DictType = DictionaryType = dict class _Cell: cell_contents = ... # type: Any -class FunctionType: +class FunctionType(object): func_closure = ... # type: Optional[Tuple[_Cell, ...]] func_code = ... # type: CodeType func_defaults = ... # type: Optional[Tuple[Any, ...]] @@ -39,7 +39,6 @@ class FunctionType: __closure__ = func_closure __code__ = func_code __defaults__ = func_defaults - __dict__ = func_dict __globals__ = func_globals __name__ = func_name def __call__(self, *args: Any, **kwargs: Any) -> Any: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 167229a34018..c47aa76ba89e 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -57,7 +57,6 @@ class type: __name__ = ... # type: str __qualname__ = ... # type: str __module__ = ... # type: str - __dict__ = ... # type: Dict[str, Any] __mro__ = ... # type: Tuple[type, ...] @overload @@ -674,11 +673,10 @@ class range(Sequence[int]): def __repr__(self) -> str: ... def __reversed__(self) -> Iterator[int]: ... -class module: +class module(object): # TODO not defined in builtins! __name__ = ... # type: str __file__ = ... # type: str - __dict__ = ... # type: Dict[str, Any] class property: def __init__(self, fget: Callable[[Any], Any] = None, diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 17e33470a1c5..bdc3ce592438 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -24,7 +24,6 @@ class FunctionType: __closure__ = ... # type: Optional[Tuple[_Cell, ...]] __code__ = ... # type: CodeType __defaults__ = ... # type: Optional[Tuple[Any, ...]] - __dict__ = ... # type: Dict[str, Any] __globals__ = ... # type: Dict[str, Any] __name__ = ... # type: str def __call__(self, *args: Any, **kwargs: Any) -> Any: ... From 706c32a0584ea17d5cd44cc511dc6ab1439c605d Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Sat, 28 Jan 2017 01:47:48 +0300 Subject: [PATCH 4/4] Added __ne__ and __eq__ to tuple instead of inherited ones from object --- stdlib/2/__builtin__.pyi | 2 ++ stdlib/3/builtins.pyi | 2 ++ 2 files changed, 4 insertions(+) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index de68294fb71c..e0e512ba5e5c 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -483,6 +483,8 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __eq__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __ne__(self, x: Tuple[_T_co, ...]) -> bool: ... def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index c47aa76ba89e..78d055363d9f 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -499,6 +499,8 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __eq__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __ne__(self, x: Tuple[_T_co, ...]) -> bool: ... def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ...