summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorMariatta <Mariatta@users.noreply.github.com>2017-05-03 16:38:01 (GMT)
committerGitHub <noreply@github.com>2017-05-03 16:38:01 (GMT)
commite612c28513b406779d187e5f816445c7d40d292b (patch)
tree299b378580ca44b77c5e65444734632931daa7d5 /Lib/test/test_typing.py
parent5bcf01d4cdc78f6b01e5017ff60da7dbfc34c36b (diff)
downloadcpython-e612c28513b406779d187e5f816445c7d40d292b.zip
cpython-e612c28513b406779d187e5f816445c7d40d292b.tar.gz
cpython-e612c28513b406779d187e5f816445c7d40d292b.tar.bz2
[3.6] bpo-28556: Routine updates to typing (GH-1366) (#1416)
- Add NoReturn type - Use WrapperDescriptorType (original PR by Jim Fasarakis-Hilliard) - Minor bug-fixes (cherry picked from commit f06e0218ef6007667f5d61184b85a81a0466d3ae)
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py51
1 files changed, 46 insertions, 5 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index f0070ec..b3cabda 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__':