|
6 | 6 | from unittest import TestCase, main, skipUnless, SkipTest |
7 | 7 | from copy import copy, deepcopy |
8 | 8 |
|
9 | | -from typing import Any |
| 9 | +from typing import Any, NoReturn |
10 | 10 | from typing import TypeVar, AnyStr |
11 | 11 | from typing import T, KT, VT # Not in __all__. |
12 | 12 | from typing import Union, Optional |
@@ -102,17 +102,47 @@ def test_cannot_instantiate(self): |
102 | 102 | with self.assertRaises(TypeError): |
103 | 103 | type(Any)() |
104 | 104 |
|
105 | | - def test_cannot_subscript(self): |
106 | | - with self.assertRaises(TypeError): |
107 | | - Any[int] |
108 | | - |
109 | 105 | def test_any_works_with_alias(self): |
110 | 106 | # These expressions must simply not fail. |
111 | 107 | typing.Match[Any] |
112 | 108 | typing.Pattern[Any] |
113 | 109 | typing.IO[Any] |
114 | 110 |
|
115 | 111 |
|
| 112 | +class NoReturnTests(BaseTestCase): |
| 113 | + |
| 114 | + def test_noreturn_instance_type_error(self): |
| 115 | + with self.assertRaises(TypeError): |
| 116 | + isinstance(42, NoReturn) |
| 117 | + |
| 118 | + def test_noreturn_subclass_type_error(self): |
| 119 | + with self.assertRaises(TypeError): |
| 120 | + issubclass(Employee, NoReturn) |
| 121 | + with self.assertRaises(TypeError): |
| 122 | + issubclass(NoReturn, Employee) |
| 123 | + |
| 124 | + def test_repr(self): |
| 125 | + self.assertEqual(repr(NoReturn), 'typing.NoReturn') |
| 126 | + |
| 127 | + def test_not_generic(self): |
| 128 | + with self.assertRaises(TypeError): |
| 129 | + NoReturn[int] |
| 130 | + |
| 131 | + def test_cannot_subclass(self): |
| 132 | + with self.assertRaises(TypeError): |
| 133 | + class A(NoReturn): |
| 134 | + pass |
| 135 | + with self.assertRaises(TypeError): |
| 136 | + class A(type(NoReturn)): |
| 137 | + pass |
| 138 | + |
| 139 | + def test_cannot_instantiate(self): |
| 140 | + with self.assertRaises(TypeError): |
| 141 | + NoReturn() |
| 142 | + with self.assertRaises(TypeError): |
| 143 | + type(NoReturn)() |
| 144 | + |
| 145 | + |
116 | 146 | class TypeVarTests(BaseTestCase): |
117 | 147 |
|
118 | 148 | def test_basic_plain(self): |
@@ -2273,6 +2303,14 @@ def _fields(self): |
2273 | 2303 | return 'no chance for this' |
2274 | 2304 | """) |
2275 | 2305 |
|
| 2306 | + with self.assertRaises(AttributeError): |
| 2307 | + exec(""" |
| 2308 | +class XMethBad2(NamedTuple): |
| 2309 | + x: int |
| 2310 | + def _source(self): |
| 2311 | + return 'no chance for this as well' |
| 2312 | +""") |
| 2313 | + |
2276 | 2314 | @skipUnless(PY36, 'Python 3.6 required') |
2277 | 2315 | def test_namedtuple_keyword_usage(self): |
2278 | 2316 | LocalEmployee = NamedTuple("LocalEmployee", name=str, age=int) |
@@ -2420,6 +2458,9 @@ def test_all(self): |
2420 | 2458 | self.assertNotIn('sys', a) |
2421 | 2459 | # Check that Text is defined. |
2422 | 2460 | self.assertIn('Text', a) |
| 2461 | + # Check previously missing classes. |
| 2462 | + self.assertIn('SupportsBytes', a) |
| 2463 | + self.assertIn('SupportsComplex', a) |
2423 | 2464 |
|
2424 | 2465 |
|
2425 | 2466 | if __name__ == '__main__': |
|
0 commit comments