From e08a5ac3676259e4b8225f7a42ea171a5319a4a6 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 4 Dec 2018 08:25:23 -0800 Subject: [PATCH] Tweak how ast.pyi imports typing (#2668) When we import typeshed internally at Dropbox, somehow the fact that these files are all stubs gets lost (it's a long story...). This causes errors like this: .../stdlib/2/ast.pyi:6: error: Name 'typing' already defined (by an import) The quickest way around this is to rename the import to _typing. --- stdlib/2/ast.pyi | 7 +++++-- stdlib/3/ast.pyi | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/stdlib/2/ast.pyi b/stdlib/2/ast.pyi index 8261a5ef2..03682ef0c 100644 --- a/stdlib/2/ast.pyi +++ b/stdlib/2/ast.pyi @@ -1,6 +1,9 @@ # Python 2.7 ast -import typing +# Rename typing to _typing, as not to conflict with typing imported +# from _ast below when loaded in an unorthodox way by the Dropbox +# internal Bazel integration. +import typing as _typing from typing import Any, Iterator, Optional, Union from _ast import * @@ -17,7 +20,7 @@ def fix_missing_locations(node: AST) -> AST: ... def get_docstring(node: AST, clean: bool = ...) -> str: ... def increment_lineno(node: AST, n: int = ...) -> AST: ... def iter_child_nodes(node: AST) -> Iterator[AST]: ... -def iter_fields(node: AST) -> Iterator[typing.Tuple[str, Any]]: ... +def iter_fields(node: AST) -> Iterator[_typing.Tuple[str, Any]]: ... def literal_eval(node_or_string: Union[str, unicode, AST]) -> Any: ... def walk(node: AST) -> Iterator[AST]: ... diff --git a/stdlib/3/ast.pyi b/stdlib/3/ast.pyi index 181ef7950..91aab538a 100644 --- a/stdlib/3/ast.pyi +++ b/stdlib/3/ast.pyi @@ -1,7 +1,10 @@ # Python 3.5 ast -import typing -from typing import Any, Union, Iterator, Optional +# Rename typing to _typing, as not to conflict with typing imported +# from _ast below when loaded in an unorthodox way by the Dropbox +# internal Bazel integration. +import typing as _typing +from typing import Any, Iterator, Optional, Union from _ast import * @@ -19,7 +22,7 @@ def fix_missing_locations(node: AST) -> AST: ... def get_docstring(node: AST, clean: bool = ...) -> str: ... def increment_lineno(node: AST, n: int = ...) -> AST: ... def iter_child_nodes(node: AST) -> Iterator[AST]: ... -def iter_fields(node: AST) -> Iterator[typing.Tuple[str, Any]]: ... +def iter_fields(node: AST) -> Iterator[_typing.Tuple[str, Any]]: ... def literal_eval(node_or_string: Union[str, AST]) -> Any: ... def walk(node: AST) -> Iterator[AST]: ...