Skip to content

Commit 552ebe9

Browse files
Abseil Teamcopybara-github
Abseil Team
authored andcommitted
Always import typing since we have dropped Python 2 support.
PiperOrigin-RevId: 542170474
1 parent 1a6806d commit 552ebe9

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

absl/testing/absltest.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import sys
4141
import tempfile
4242
import textwrap
43+
import typing
44+
from typing import Any, AnyStr, BinaryIO, Callable, ContextManager, IO, Iterator, List, Mapping, MutableMapping, MutableSequence, NoReturn, Optional, Sequence, Text, TextIO, Tuple, Type, Union
4345
import unittest
4446
from unittest import mock # pylint: disable=unused-import Allow absltest.mock.
4547
from urllib import parse
@@ -50,25 +52,15 @@
5052
from absl.testing import _pretty_print_reporter
5153
from absl.testing import xml_reporter
5254

53-
# pylint: disable=g-import-not-at-top
54-
# Make typing an optional import to avoid it being a required dependency
55-
# in Python 2. Type checkers will still understand the imports.
56-
try:
57-
# pylint: disable=unused-import
58-
import typing
59-
from typing import Any, AnyStr, BinaryIO, Callable, ContextManager, IO, Iterator, List, Mapping, MutableMapping, MutableSequence, NoReturn, Optional, Sequence, Text, TextIO, Tuple, Type, Union
60-
# pylint: enable=unused-import
61-
except ImportError:
62-
pass
63-
else:
64-
# Use an if-type-checking block to prevent leakage of type-checking only
65-
# symbols. We don't want people relying on these at runtime.
66-
if typing.TYPE_CHECKING:
67-
# Unbounded TypeVar for general usage
68-
_T = typing.TypeVar('_T')
69-
70-
import unittest.case
71-
_OutcomeType = unittest.case._Outcome # pytype: disable=module-attr
55+
# Use an if-type-checking block to prevent leakage of type-checking only
56+
# symbols. We don't want people relying on these at runtime.
57+
if typing.TYPE_CHECKING:
58+
# Unbounded TypeVar for general usage
59+
_T = typing.TypeVar('_T')
60+
61+
import unittest.case # pylint: disable=g-import-not-at-top,g-bad-import-order
62+
63+
_OutcomeType = unittest.case._Outcome # pytype: disable=module-attr
7264

7365

7466
# pylint: enable=g-import-not-at-top

0 commit comments

Comments
 (0)