From f667f8feeeb46eac218d92b516ff3613cd395b61 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 30 Oct 2016 02:04:49 +0200 Subject: [PATCH 1/2] Consider __doc__ always Optional. Fixes issues surfaced with python/mypy#2380. --- README.md | 2 +- stdlib/2/__builtin__.pyi | 2 +- stdlib/2/abc.pyi | 4 ++-- stdlib/2/ast.pyi | 6 +++--- stdlib/2/optparse.pyi | 12 ++++++------ stdlib/2/tempfile.pyi | 4 ++-- stdlib/3/ast.pyi | 6 +++--- stdlib/3/builtins.pyi | 2 +- third_party/3/typed_ast/ast27.pyi | 4 ++-- third_party/3/typed_ast/ast35.pyi | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4147d03454ad..19bc091c5ff7 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ The below is an excerpt from the types for the `datetime` module. ``` MAXYEAR = ... # type: int MINYEAR = ... # type: int -__doc__ = ... # type: str +__doc__ = ... # type: Optional[str] __file__ = ... # type: str __name__ = ... # type: str __package__ = ... # type: None diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 06793fabd0b4..e051f000aa34 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -26,7 +26,7 @@ class staticmethod: pass # Special, only valid as a decorator. class classmethod: pass # Special, only valid as a decorator. class object: - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] __class__ = ... # type: type def __init__(self) -> None: ... diff --git a/stdlib/2/abc.pyi b/stdlib/2/abc.pyi index 0eb26f01897e..5cd4a16d756c 100644 --- a/stdlib/2/abc.pyi +++ b/stdlib/2/abc.pyi @@ -12,7 +12,7 @@ def abstractmethod(funcobj: Any) -> Any: ... class ABCMeta(type): # TODO: FrozenSet __abstractmethods__ = ... # type: Set[Any] - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] _abc_cache = ... # type: _weakrefset.WeakSet _abc_invalidation_counter = ... # type: int _abc_negative_cache = ... # type: _weakrefset.WeakSet @@ -31,7 +31,7 @@ class _C: # TODO: The real abc.abstractproperty inherits from "property". class abstractproperty(object): def __new__(cls, func: Any) -> Any: ... - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] __isabstractmethod__ = ... # type: bool doc = ... # type: Any fdel = ... # type: Any diff --git a/stdlib/2/ast.pyi b/stdlib/2/ast.pyi index 6e11445f798a..f86a318a9a9e 100644 --- a/stdlib/2/ast.pyi +++ b/stdlib/2/ast.pyi @@ -1,7 +1,7 @@ # Python 2.7 ast import typing -from typing import Any, Iterator, Union +from typing import Any, Iterator, Union, Optional from _ast import ( Add, alias, And, arguments, Assert, Assign, AST, Attribute, AugAssign, @@ -33,12 +33,12 @@ def literal_eval(node_or_string: Union[str, AST]) -> Any: ... def walk(node: AST) -> Iterator[AST]: ... class NodeVisitor(): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] def generic_visit(self, node: AST) -> None: ... diff --git a/stdlib/2/optparse.pyi b/stdlib/2/optparse.pyi index e315ac4796e7..0709478d320d 100644 --- a/stdlib/2/optparse.pyi +++ b/stdlib/2/optparse.pyi @@ -18,7 +18,7 @@ class OptParseError(Exception): def __init__(self, msg) -> None: ... class BadOptionError(OptParseError): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] opt_str = ... # type: Any def __init__(self, opt_str) -> None: ... @@ -65,7 +65,7 @@ class HelpFormatter: def store_option_strings(self, parser) -> None: ... class IndentedHelpFormatter(HelpFormatter): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] _long_opt_fmt = ... # type: str _short_opt_fmt = ... # type: str current_indent = ... # type: int @@ -93,7 +93,7 @@ class Option: TYPED_ACTIONS = ... # type: Tuple[str, ...] TYPES = ... # type: Tuple[str, ...] TYPE_CHECKER = ... # type: Dict[str, Callable] - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] _long_opts = ... # type: List[Text] _short_opts = ... # type: List[Text] action = ... # type: str @@ -162,7 +162,7 @@ class OptionGroup(OptionContainer): def set_title(self, title) -> None: ... class OptionParser(OptionContainer): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] _long_opt = ... # type: Dict[Text, Any] _short_opt = ... # type: Dict[Any, Any] allow_interspersed_args = ... # type: bool @@ -220,11 +220,11 @@ class OptionParser(OptionContainer): def set_usage(self, usage: Text) -> None: ... class OptionValueError(OptParseError): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] msg = ... # type: Any class TitledHelpFormatter(HelpFormatter): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] _long_opt_fmt = ... # type: str _short_opt_fmt = ... # type: str current_indent = ... # type: int diff --git a/stdlib/2/tempfile.pyi b/stdlib/2/tempfile.pyi index 320f7f46a200..1cbd47a3daae 100644 --- a/stdlib/2/tempfile.pyi +++ b/stdlib/2/tempfile.pyi @@ -19,7 +19,7 @@ template = ... # type: str _name_sequence = ... # type: Optional[_RandomNameSequence] class _RandomNameSequence: - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] _rng = ... # type: random.Random _rng_pid = ... # type: int characters = ... # type: str @@ -31,7 +31,7 @@ class _RandomNameSequence: def normcase(path: AnyStr) -> AnyStr: ... class _TemporaryFileWrapper(IO[str]): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] close_called = ... # type: bool delete = ... # type: bool file = ... # type: IO diff --git a/stdlib/3/ast.pyi b/stdlib/3/ast.pyi index ac803687ae2b..79a0e878eb7f 100644 --- a/stdlib/3/ast.pyi +++ b/stdlib/3/ast.pyi @@ -1,7 +1,7 @@ # Python 3.5 ast import typing -from typing import Any, Union, Iterator +from typing import Any, Union, Iterator, Optional from _ast import ( Add, alias, And, arg, arguments, Assert, Assign, AST, AsyncFor, @@ -19,12 +19,12 @@ from _ast import ( ) class NodeVisitor(): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] def generic_visit(self, node: AST) -> None: ... def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 42b6e24bed18..28162d736f36 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -27,7 +27,7 @@ class staticmethod: pass # Special, only valid as a decorator. class classmethod: pass # Special, only valid as a decorator. class object: - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] __class__ = ... # type: type __dict__ = ... # type: Dict[str, Any] diff --git a/third_party/3/typed_ast/ast27.pyi b/third_party/3/typed_ast/ast27.pyi index 163b6a2e91c5..4f459961f9ca 100644 --- a/third_party/3/typed_ast/ast27.pyi +++ b/third_party/3/typed_ast/ast27.pyi @@ -2,12 +2,12 @@ import typing from typing import Any, Optional, Union, Generic, Iterator class NodeVisitor(): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] def generic_visit(self, node: AST) -> None: ... def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ... diff --git a/third_party/3/typed_ast/ast35.pyi b/third_party/3/typed_ast/ast35.pyi index 04e8a295d19f..e7d84aa287f0 100644 --- a/third_party/3/typed_ast/ast35.pyi +++ b/third_party/3/typed_ast/ast35.pyi @@ -2,12 +2,12 @@ import typing from typing import Any, Optional, Union, Generic, Iterator class NodeVisitor(): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - __doc__ = ... # type: str + __doc__ = ... # type: Optional[str] def generic_visit(self, node: AST) -> None: ... def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ... From c16693e7ab079a1198e660c8dd3a73e2e62fc60a Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 30 Oct 2016 18:52:05 +0100 Subject: [PATCH 2/2] Remove all __doc__ entries which already inherit the field from 'object' --- README.md | 4 ---- stdlib/2/abc.pyi | 2 -- stdlib/2/ast.pyi | 4 +--- stdlib/2/optparse.pyi | 6 ------ stdlib/2/tempfile.pyi | 2 -- stdlib/2/types.pyi | 1 - stdlib/3/_importlib_modulespec.pyi | 1 - stdlib/3/ast.pyi | 4 +--- stdlib/3/types.pyi | 1 - third_party/2/sqlalchemy/util/langhelpers.pyi | 2 -- third_party/3/typed_ast/ast27.pyi | 2 -- third_party/3/typed_ast/ast35.pyi | 2 -- 12 files changed, 2 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 19bc091c5ff7..25203a09c830 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,6 @@ The below is an excerpt from the types for the `datetime` module. ``` MAXYEAR = ... # type: int MINYEAR = ... # type: int -__doc__ = ... # type: Optional[str] -__file__ = ... # type: str -__name__ = ... # type: str -__package__ = ... # type: None class date(object): def __init__(self, year: int, month: int, day: int) -> None: ... diff --git a/stdlib/2/abc.pyi b/stdlib/2/abc.pyi index 5cd4a16d756c..3ae3b522bf0b 100644 --- a/stdlib/2/abc.pyi +++ b/stdlib/2/abc.pyi @@ -12,7 +12,6 @@ def abstractmethod(funcobj: Any) -> Any: ... class ABCMeta(type): # TODO: FrozenSet __abstractmethods__ = ... # type: Set[Any] - __doc__ = ... # type: Optional[str] _abc_cache = ... # type: _weakrefset.WeakSet _abc_invalidation_counter = ... # type: int _abc_negative_cache = ... # type: _weakrefset.WeakSet @@ -31,7 +30,6 @@ class _C: # TODO: The real abc.abstractproperty inherits from "property". class abstractproperty(object): def __new__(cls, func: Any) -> Any: ... - __doc__ = ... # type: Optional[str] __isabstractmethod__ = ... # type: bool doc = ... # type: Any fdel = ... # type: Any diff --git a/stdlib/2/ast.pyi b/stdlib/2/ast.pyi index f86a318a9a9e..5bad0bc5796c 100644 --- a/stdlib/2/ast.pyi +++ b/stdlib/2/ast.pyi @@ -1,7 +1,7 @@ # Python 2.7 ast import typing -from typing import Any, Iterator, Union, Optional +from typing import Any, Iterator, Union from _ast import ( Add, alias, And, arguments, Assert, Assign, AST, Attribute, AugAssign, @@ -33,12 +33,10 @@ def literal_eval(node_or_string: Union[str, AST]) -> Any: ... def walk(node: AST) -> Iterator[AST]: ... class NodeVisitor(): - __doc__ = ... # type: Optional[str] def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - __doc__ = ... # type: Optional[str] def generic_visit(self, node: AST) -> None: ... diff --git a/stdlib/2/optparse.pyi b/stdlib/2/optparse.pyi index 0709478d320d..eb753b23b0bd 100644 --- a/stdlib/2/optparse.pyi +++ b/stdlib/2/optparse.pyi @@ -18,7 +18,6 @@ class OptParseError(Exception): def __init__(self, msg) -> None: ... class BadOptionError(OptParseError): - __doc__ = ... # type: Optional[str] opt_str = ... # type: Any def __init__(self, opt_str) -> None: ... @@ -65,7 +64,6 @@ class HelpFormatter: def store_option_strings(self, parser) -> None: ... class IndentedHelpFormatter(HelpFormatter): - __doc__ = ... # type: Optional[str] _long_opt_fmt = ... # type: str _short_opt_fmt = ... # type: str current_indent = ... # type: int @@ -93,7 +91,6 @@ class Option: TYPED_ACTIONS = ... # type: Tuple[str, ...] TYPES = ... # type: Tuple[str, ...] TYPE_CHECKER = ... # type: Dict[str, Callable] - __doc__ = ... # type: Optional[str] _long_opts = ... # type: List[Text] _short_opts = ... # type: List[Text] action = ... # type: str @@ -162,7 +159,6 @@ class OptionGroup(OptionContainer): def set_title(self, title) -> None: ... class OptionParser(OptionContainer): - __doc__ = ... # type: Optional[str] _long_opt = ... # type: Dict[Text, Any] _short_opt = ... # type: Dict[Any, Any] allow_interspersed_args = ... # type: bool @@ -220,11 +216,9 @@ class OptionParser(OptionContainer): def set_usage(self, usage: Text) -> None: ... class OptionValueError(OptParseError): - __doc__ = ... # type: Optional[str] msg = ... # type: Any class TitledHelpFormatter(HelpFormatter): - __doc__ = ... # type: Optional[str] _long_opt_fmt = ... # type: str _short_opt_fmt = ... # type: str current_indent = ... # type: int diff --git a/stdlib/2/tempfile.pyi b/stdlib/2/tempfile.pyi index 1cbd47a3daae..ca2d4b475ecc 100644 --- a/stdlib/2/tempfile.pyi +++ b/stdlib/2/tempfile.pyi @@ -19,7 +19,6 @@ template = ... # type: str _name_sequence = ... # type: Optional[_RandomNameSequence] class _RandomNameSequence: - __doc__ = ... # type: Optional[str] _rng = ... # type: random.Random _rng_pid = ... # type: int characters = ... # type: str @@ -31,7 +30,6 @@ class _RandomNameSequence: def normcase(path: AnyStr) -> AnyStr: ... class _TemporaryFileWrapper(IO[str]): - __doc__ = ... # type: Optional[str] close_called = ... # type: bool delete = ... # type: bool file = ... # type: IO diff --git a/stdlib/2/types.pyi b/stdlib/2/types.pyi index 607d9fac1c3f..c3b66f40e95f 100644 --- a/stdlib/2/types.pyi +++ b/stdlib/2/types.pyi @@ -40,7 +40,6 @@ class FunctionType: __code__ = func_code __defaults__ = func_defaults __dict__ = func_dict - __doc__ = func_doc __globals__ = func_globals __name__ = func_name def __call__(self, *args: Any, **kwargs: Any) -> Any: ... diff --git a/stdlib/3/_importlib_modulespec.pyi b/stdlib/3/_importlib_modulespec.pyi index 20d889471400..a48baa59c774 100644 --- a/stdlib/3/_importlib_modulespec.pyi +++ b/stdlib/3/_importlib_modulespec.pyi @@ -26,7 +26,6 @@ if sys.version_info >= (3, 4): class ModuleType: __name__ = ... # type: str __file__ = ... # type: str - __doc__ = ... # type: Optional[str] if sys.version_info >= (3, 4): __loader__ = ... # type: Optional[Loader] __package__ = ... # type: Optional[str] diff --git a/stdlib/3/ast.pyi b/stdlib/3/ast.pyi index 79a0e878eb7f..86a8431accd8 100644 --- a/stdlib/3/ast.pyi +++ b/stdlib/3/ast.pyi @@ -1,7 +1,7 @@ # Python 3.5 ast import typing -from typing import Any, Union, Iterator, Optional +from typing import Any, Union, Iterator from _ast import ( Add, alias, And, arg, arguments, Assert, Assign, AST, AsyncFor, @@ -19,12 +19,10 @@ from _ast import ( ) class NodeVisitor(): - __doc__ = ... # type: Optional[str] def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - __doc__ = ... # type: Optional[str] def generic_visit(self, node: AST) -> None: ... def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ... diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 1026cb1c7743..4a0da754e867 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -21,7 +21,6 @@ class FunctionType: __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: ... diff --git a/third_party/2/sqlalchemy/util/langhelpers.pyi b/third_party/2/sqlalchemy/util/langhelpers.pyi index c16b1f91c754..c688ba33dfb5 100644 --- a/third_party/2/sqlalchemy/util/langhelpers.pyi +++ b/third_party/2/sqlalchemy/util/langhelpers.pyi @@ -48,7 +48,6 @@ def as_interface(obj, cls=..., methods=..., required=...): ... class memoized_property: fget = ... # type: Any - __doc__ = ... # type: Any __name__ = ... # type: Any def __init__(self, fget, doc=...) -> None: ... def __get__(self, obj, cls): ... @@ -92,7 +91,6 @@ def assert_arg_type(arg, argtype, name): ... def dictlike_iteritems(dictlike): ... class classproperty: - __doc__ = ... # type: Any def __init__(self, fget, *arg, **kw) -> None: ... def __get__(desc, self, cls): ... diff --git a/third_party/3/typed_ast/ast27.pyi b/third_party/3/typed_ast/ast27.pyi index 4f459961f9ca..dd26314e6b65 100644 --- a/third_party/3/typed_ast/ast27.pyi +++ b/third_party/3/typed_ast/ast27.pyi @@ -2,12 +2,10 @@ import typing from typing import Any, Optional, Union, Generic, Iterator class NodeVisitor(): - __doc__ = ... # type: Optional[str] def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - __doc__ = ... # type: Optional[str] def generic_visit(self, node: AST) -> None: ... def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ... diff --git a/third_party/3/typed_ast/ast35.pyi b/third_party/3/typed_ast/ast35.pyi index e7d84aa287f0..2a18ff7d88aa 100644 --- a/third_party/3/typed_ast/ast35.pyi +++ b/third_party/3/typed_ast/ast35.pyi @@ -2,12 +2,10 @@ import typing from typing import Any, Optional, Union, Generic, Iterator class NodeVisitor(): - __doc__ = ... # type: Optional[str] def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - __doc__ = ... # type: Optional[str] def generic_visit(self, node: AST) -> None: ... def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ...