From b1a0e561d00d1b4c02c74c50b740ab4b61e695bf Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Thu, 8 Oct 2020 15:22:21 -0700 Subject: [PATCH 1/2] Add a version guard for importing enum. I'm trying to pull the latest version of typeshed into Google, and pytype chokes on pstats in Python 2 because the enum module was introduced in 3.4. --- stdlib/2and3/pstats.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/2and3/pstats.pyi b/stdlib/2and3/pstats.pyi index 68c937e2725c..b393d8b6fa64 100644 --- a/stdlib/2and3/pstats.pyi +++ b/stdlib/2and3/pstats.pyi @@ -1,10 +1,12 @@ import sys from _typeshed import AnyPath from cProfile import Profile as _cProfile -from enum import Enum from profile import Profile from typing import IO, Any, Dict, Iterable, List, Optional, Text, Tuple, TypeVar, Union, overload +if sys.version_info >= (3, 4): + from enum import Enum + _Selector = Union[str, float, int] _T = TypeVar("_T", bound=Stats) From 6ce920cf051a85034fd83a87953c115da3084af7 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Thu, 8 Oct 2020 15:40:30 -0700 Subject: [PATCH 2/2] Move the enum import into the branch that defines SortKey. --- stdlib/2and3/pstats.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/2and3/pstats.pyi b/stdlib/2and3/pstats.pyi index b393d8b6fa64..9c74aeb9c3de 100644 --- a/stdlib/2and3/pstats.pyi +++ b/stdlib/2and3/pstats.pyi @@ -4,13 +4,11 @@ from cProfile import Profile as _cProfile from profile import Profile from typing import IO, Any, Dict, Iterable, List, Optional, Text, Tuple, TypeVar, Union, overload -if sys.version_info >= (3, 4): - from enum import Enum - _Selector = Union[str, float, int] _T = TypeVar("_T", bound=Stats) if sys.version_info >= (3, 7): + from enum import Enum class SortKey(str, Enum): CALLS: str CUMULATIVE: str