mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
bpo-34776: Fix dataclasses to support __future__ "annotations" mode (#9518)
This commit is contained in:
parent
bba873e633
commit
d219cc4180
4 changed files with 78 additions and 34 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue