bpo-34776: Fix dataclasses to support __future__ "annotations" mode (#9518)

This commit is contained in:
Yury Selivanov 2019-12-09 09:54:20 -05:00 committed by Łukasz Langa
parent bba873e633
commit d219cc4180
4 changed files with 78 additions and 34 deletions

View file

@ -10,6 +10,7 @@ import builtins
import unittest
from unittest.mock import Mock
from typing import ClassVar, Any, List, Union, Tuple, Dict, Generic, TypeVar, Optional
from typing import get_type_hints
from collections import deque, OrderedDict, namedtuple
from functools import total_ordering
@ -2926,6 +2927,17 @@ class TestStringAnnotations(unittest.TestCase):
# won't exist on the instance.
self.assertNotIn('not_iv4', c.__dict__)
def test_text_annotations(self):
from test import dataclass_textanno
self.assertEqual(
get_type_hints(dataclass_textanno.Bar),
{'foo': dataclass_textanno.Foo})
self.assertEqual(
get_type_hints(dataclass_textanno.Bar.__init__),
{'foo': dataclass_textanno.Foo,
'return': type(None)})
class TestMakeDataclass(unittest.TestCase):
def test_simple(self):