|
40 | 40 | import sys
|
41 | 41 | import tempfile
|
42 | 42 | 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 |
43 | 45 | import unittest
|
44 | 46 | from unittest import mock # pylint: disable=unused-import Allow absltest.mock.
|
45 | 47 | from urllib import parse
|
|
50 | 52 | from absl.testing import _pretty_print_reporter
|
51 | 53 | from absl.testing import xml_reporter
|
52 | 54 |
|
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 |
72 | 64 |
|
73 | 65 |
|
74 | 66 | # pylint: enable=g-import-not-at-top
|
|
0 commit comments