cpython: 9e65bc305a24 (original) (raw)

--- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -378,6 +378,16 @@ class CallableTests(BaseTestCase): with self.assertRaises(TypeError): type(c)()

+ def test_callable_instance_works(self): def f(): pass @@ -1296,9 +1306,10 @@ PY36 = sys.version_info[:2] >= (3, 6) PY36_TESTS = """ from test import ann_module, ann_module2, ann_module3 -from collections import ChainMap -class B: +class A:

+class B(A): x: ClassVar[Optional['B']] = None y: int class CSub(B): @@ -1317,6 +1328,15 @@ if PY36: gth = get_type_hints class GetTypeHintTests(BaseTestCase):

+ @skipUnless(PY36, 'Python 3.6 required') def test_get_type_hints_modules(self): self.assertEqual(gth(ann_module), {1: 2, 'f': Tuple[int, int], 'x': int, 'y': str}) @@ -1326,18 +1346,15 @@ class GetTypeHintTests(BaseTestCase): @skipUnless(PY36, 'Python 3.6 required') def test_get_type_hints_classes(self): self.assertEqual(gth(ann_module.C, ann_module.dict),

@skipUnless(PY36, 'Python 3.6 required') @@ -1355,20 +1372,34 @@ class GetTypeHintTests(BaseTestCase): class Der(ABase): ... self.assertEqual(gth(ABase.meth), {'x': int})

def test_previous_behavior(self): def testf(x, y): ... testf.annotations['x'] = 'int' self.assertEqual(gth(testf), {'x': int})

+ @skipUnless(PY36, 'Python 3.6 required') def test_get_type_hints_ClassVar(self):

class CollectionsAbcTests(BaseTestCase):

--- a/Lib/typing.py +++ b/Lib/typing.py @@ -10,8 +10,6 @@ try: import collections.abc as collections_abc except ImportError: import collections as collections_abc # Fallback for PY3.2. -if sys.version_info[:2] >= (3, 3):

Please keep all alphabetized within each category.

@@ -1194,14 +1192,12 @@ class CallableMeta(GenericMeta): # super()._tree_repr() for nice formatting. arg_list = [] for arg in tree[1:]:

@@ -1216,26 +1212,22 @@ class CallableMeta(GenericMeta): raise TypeError("Callable must be used as " "Callable[[arg, ...], result].") args, result = parameters

@_tp_cache def getitem_inner(self, parameters):

@@ -1332,7 +1324,11 @@ def cast(typ, val): def _get_defaults(func): """Internal helper to extract the default arguments, by name."""

-

-

-

-

-

-

-

-

+def get_type_hints(obj, globalns=None, localns=None):

+

+

+

+

+

+

+

+

-

-

-

-

- -else:

-

-

-

-

-

def no_type_check(arg): @@ -2160,7 +2098,7 @@ class TextIO(IO[str]): pass @abstractproperty

@abstractproperty