cpython: 1e49abb03e0f (original) (raw)
Mercurial > cpython
changeset 105188:1e49abb03e0f 3.5
Issue #28556: two more small upstream changes by Ivan Levkivskyi (#329, #330) [#28556]
Guido van Rossum guido@python.org | |
---|---|
date | Sat, 19 Nov 2016 10:32:41 -0800 |
parents | 20f62e4a9c2f |
children | cdddf4ee0e00 02f416441def |
files | Lib/test/test_typing.py Lib/typing.py |
diffstat | 2 files changed, 21 insertions(+), 2 deletions(-)[+] [-] Lib/test/test_typing.py 21 Lib/typing.py 2 |
line wrap: on
line diff
--- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -45,6 +45,10 @@ class BaseTestCase(TestCase): message += ' : %s' % msg raise self.failureException(message)
+ class Employee: pass @@ -509,6 +513,13 @@ class ProtocolTests(BaseTestCase): def test_protocol_instance_type_error(self): with self.assertRaises(TypeError): isinstance(0, typing.SupportsAbs)
class C1(typing.SupportsInt):[](#l1.18)
def __int__(self) -> int:[](#l1.19)
return 42[](#l1.20)
class C2(C1):[](#l1.21)
pass[](#l1.22)
c = C2()[](#l1.23)
self.assertIsInstance(c, C1)[](#l1.24)
class GenericTests(BaseTestCase): @@ -748,8 +759,12 @@ class GenericTests(BaseTestCase): class CC: ... self.assertEqual(get_type_hints(foobar, globals(), locals()), {'x': List[List[CC]]}) T = TypeVar('T')
def barfoo(x: Tuple[T, ...]): ...[](#l1.32)
self.assertIs(get_type_hints(barfoo, globals(), locals())['x'], Tuple[T, ...])[](#l1.33)
AT = Tuple[T, ...][](#l1.34)
def barfoo(x: AT): ...[](#l1.35)
self.assertIs(get_type_hints(barfoo, globals(), locals())['x'], AT)[](#l1.36)
CT = Callable[..., List[T]][](#l1.37)
def barfoo2(x: CT): ...[](#l1.38)
self.assertIs(get_type_hints(barfoo2, globals(), locals())['x'], CT)[](#l1.39)
def test_extended_generic_rules_subclassing(self): class T1(Tuple[T, KT]): ... @@ -800,6 +815,8 @@ class GenericTests(BaseTestCase): def test_type_erasure_special(self): T = TypeVar('T')
# this is the only test that checks type caching[](#l1.47)
self.clear_caches()[](#l1.48) class MyTup(Tuple[T, T]): ...[](#l1.49) self.assertIs(MyTup[int]().__class__, MyTup)[](#l1.50) self.assertIs(MyTup[int]().__orig_class__, MyTup[int])[](#l1.51)
--- a/Lib/typing.py +++ b/Lib/typing.py @@ -1503,6 +1503,8 @@ class _ProtocolMeta(GenericMeta): """ def instancecheck(self, obj):
if _Protocol not in self.__bases__:[](#l2.7)
return super().__instancecheck__(obj)[](#l2.8) raise TypeError("Protocols cannot be used with isinstance().")[](#l2.9)