|
20 | 20 |
|
21 | 21 | from typing import Any, NoReturn, Never, assert_never |
22 | 22 | from typing import overload, get_overloads, clear_overloads |
23 | | -from typing import TypeVar, TypeVarTuple, Unpack, AnyStr |
| 23 | +from typing import TypeVar, TypeVarTuple, Unpack |
24 | 24 | from typing import T, KT, VT # Not in __all__. |
25 | 25 | from typing import Union, Optional, Literal |
26 | 26 | from typing import Tuple, List, Dict, MutableMapping |
|
49 | 49 | import weakref |
50 | 50 | import types |
51 | 51 |
|
| 52 | +with warnings.catch_warnings(): |
| 53 | + warnings.simplefilter("ignore", DeprecationWarning) |
| 54 | + |
| 55 | + from typing import AnyStr |
| 56 | + |
52 | 57 | from test.support import ( |
53 | 58 | captured_stderr, cpython_only, requires_docstrings, import_helper, run_code, |
54 | 59 | subTests, EqualToForwardRef, |
@@ -9551,12 +9556,16 @@ def test_no_isinstance(self): |
9551 | 9556 | class IOTests(BaseTestCase): |
9552 | 9557 |
|
9553 | 9558 | def test_io(self): |
9554 | | - |
9555 | 9559 | def stuff(a: IO) -> AnyStr: |
9556 | 9560 | return a.readline() |
9557 | 9561 |
|
9558 | 9562 | a = stuff.__annotations__['a'] |
9559 | | - self.assertEqual(a.__parameters__, (AnyStr,)) |
| 9563 | + self.assertEqual(len(a.__parameters__), 1) |
| 9564 | + any_str = a.__parameters__[0] |
| 9565 | + self.assertEqual(repr(any_str), 'AnyStr') |
| 9566 | + self.assertEqual(any_str.__bound__, None) |
| 9567 | + self.assertEqual(any_str.__constraints__, (bytes, str)) |
| 9568 | + self.assertEqual(any_str.__constraints__, AnyStr.__constraints__) |
9560 | 9569 |
|
9561 | 9570 | def test_textio(self): |
9562 | 9571 |
|
@@ -11176,13 +11185,20 @@ def test_all_exported_names(self): |
11176 | 11185 | # there's a few types and metaclasses that aren't exported |
11177 | 11186 | not k.endswith(('Meta', '_contra', '_co')) and |
11178 | 11187 | not k.upper() == k and |
11179 | | - k not in {"ByteString"} and |
| 11188 | + k not in {"ByteString", "AnyStr"} and |
11180 | 11189 | # but export all other things that have __module__ == 'typing' |
11181 | 11190 | getattr(v, '__module__', None) == typing.__name__ |
11182 | 11191 | ) |
11183 | 11192 | } |
11184 | 11193 | self.assertSetEqual(computed_all, actual_all) |
11185 | 11194 |
|
| 11195 | + def test_any_str_deprecated(self): |
| 11196 | + # gh-105578 |
| 11197 | + fresh = import_helper.import_fresh_module('typing') |
| 11198 | + |
| 11199 | + with self.assertWarnsRegex(DeprecationWarning, r'typing\.AnyStr'): |
| 11200 | + fresh.AnyStr |
| 11201 | + |
11186 | 11202 |
|
11187 | 11203 | class TypeIterationTests(BaseTestCase): |
11188 | 11204 | _UNITERABLE_TYPES = ( |
|
0 commit comments