diff options
| author | Ivan Levkivskyi <levkivskyi@gmail.com> | 2017-05-02 17:14:07 (GMT) |
|---|---|---|
| committer | Mariatta <Mariatta@users.noreply.github.com> | 2017-05-02 17:14:07 (GMT) |
| commit | f06e0218ef6007667f5d61184b85a81a0466d3ae (patch) | |
| tree | 79f8d61eb84269181ba0eddbe4a8f0b9800e33cc /Lib/test | |
| parent | 495b5021e73e3c4b6404417ecf4fa83aa10297f0 (diff) | |
| download | cpython-f06e0218ef6007667f5d61184b85a81a0466d3ae.zip cpython-f06e0218ef6007667f5d61184b85a81a0466d3ae.tar.gz cpython-f06e0218ef6007667f5d61184b85a81a0466d3ae.tar.bz2 | |
bpo-28556: Routine updates to typing (#1366)
- Add NoReturn type
- Use WrapperDescriptorType (original PR by Jim Fasarakis-Hilliard)
- Minor bug-fixes
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_typing.py | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 20fc221..33d553e 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -6,7 +6,7 @@ import sys from unittest import TestCase, main, skipUnless, SkipTest from copy import copy, deepcopy -from typing import Any +from typing import Any, NoReturn from typing import TypeVar, AnyStr from typing import T, KT, VT # Not in __all__. from typing import Union, Optional @@ -102,10 +102,6 @@ class AnyTests(BaseTestCase): with self.assertRaises(TypeError): type(Any)() - def test_cannot_subscript(self): - with self.assertRaises(TypeError): - Any[int] - def test_any_works_with_alias(self): # These expressions must simply not fail. typing.Match[Any] @@ -113,6 +109,40 @@ class AnyTests(BaseTestCase): typing.IO[Any] +class NoReturnTests(BaseTestCase): + + def test_noreturn_instance_type_error(self): + with self.assertRaises(TypeError): + isinstance(42, NoReturn) + + def test_noreturn_subclass_type_error(self): + with self.assertRaises(TypeError): + issubclass(Employee, NoReturn) + with self.assertRaises(TypeError): + issubclass(NoReturn, Employee) + + def test_repr(self): + self.assertEqual(repr(NoReturn), 'typing.NoReturn') + + def test_not_generic(self): + with self.assertRaises(TypeError): + NoReturn[int] + + def test_cannot_subclass(self): + with self.assertRaises(TypeError): + class A(NoReturn): + pass + with self.assertRaises(TypeError): + class A(type(NoReturn)): + pass + + def test_cannot_instantiate(self): + with self.assertRaises(TypeError): + NoReturn() + with self.assertRaises(TypeError): + type(NoReturn)() + + class TypeVarTests(BaseTestCase): def test_basic_plain(self): @@ -2273,6 +2303,14 @@ class XMethBad(NamedTuple): return 'no chance for this' """) + with self.assertRaises(AttributeError): + exec(""" +class XMethBad2(NamedTuple): + x: int + def _source(self): + return 'no chance for this as well' +""") + @skipUnless(PY36, 'Python 3.6 required') def test_namedtuple_keyword_usage(self): LocalEmployee = NamedTuple("LocalEmployee", name=str, age=int) @@ -2420,6 +2458,9 @@ class AllTests(BaseTestCase): self.assertNotIn('sys', a) # Check that Text is defined. self.assertIn('Text', a) + # Check previously missing classes. + self.assertIn('SupportsBytes', a) + self.assertIn('SupportsComplex', a) if __name__ == '__main__': |
