From 39576c5d413041fa3f3327b85af77a31fccf4a6c Mon Sep 17 00:00:00 2001 From: Thomas Schaper Date: Mon, 7 May 2018 20:20:20 +0200 Subject: [PATCH] Fix signature of generic_visit method (#2100) This methods returns something that has the same type as the first argument. Fixes #2085. --- stdlib/2/ast.pyi | 5 +++-- stdlib/3/ast.pyi | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/stdlib/2/ast.pyi b/stdlib/2/ast.pyi index e4ba3b6f1..aff644337 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, TypeVar, Union from _ast import * from _ast import AST, Module @@ -9,6 +9,7 @@ from _ast import AST, Module __version__ = ... # type: str PyCF_ONLY_AST = ... # type: int +_T = TypeVar('_T', bound=AST) def parse(source: Union[str, unicode], filename: Union[str, unicode] = ..., mode: Union[str, unicode] = ...) -> Module: ... def copy_location(new_node: AST, old_node: AST) -> AST: ... @@ -26,4 +27,4 @@ class NodeVisitor(): def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - def generic_visit(self, node: AST) -> None: ... + def generic_visit(self, node: _T) -> _T: ... diff --git a/stdlib/3/ast.pyi b/stdlib/3/ast.pyi index 241f874f1..69999dcac 100644 --- a/stdlib/3/ast.pyi +++ b/stdlib/3/ast.pyi @@ -1,16 +1,18 @@ # Python 3.5 ast import typing -from typing import Any, Union, Iterator +from typing import Any, Union, TypeVar, Iterator from _ast import * +_T = TypeVar('_T', bound=AST) + class NodeVisitor(): def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ... class NodeTransformer(NodeVisitor): - def generic_visit(self, node: AST) -> None: ... + def generic_visit(self, node: _T) -> _T: ... def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> Module: ... def copy_location(new_node: AST, old_node: AST) -> AST: ...