|
49 | 49 | ShareableList = None |
50 | 50 | from os import DirEntry |
51 | 51 | from re import Pattern, Match |
52 | | -from types import GenericAlias, MappingProxyType, AsyncGeneratorType, CoroutineType, GeneratorType |
| 52 | +from types import ( |
| 53 | + AsyncGeneratorType, CoroutineType, GeneratorType, GenericAlias, |
| 54 | + MappingProxyType, |
| 55 | +) |
53 | 56 | from tempfile import TemporaryDirectory, SpooledTemporaryFile |
54 | 57 | from urllib.parse import SplitResult, ParseResult |
55 | 58 | from unittest.case import _AssertRaisesContext |
|
98 | 101 | ] |
99 | 102 |
|
100 | 103 |
|
| 104 | +def generic_function[T](): |
| 105 | + pass |
| 106 | + |
| 107 | + |
| 108 | +class GenericMethod: |
| 109 | + def method[T](self): |
| 110 | + pass |
| 111 | + |
| 112 | + |
101 | 113 | class BaseTest(unittest.TestCase): |
102 | 114 | """Test basics.""" |
103 | 115 | generic_types = [type, tuple, list, dict, frozendict, |
104 | 116 | set, frozenset, enumerate, memoryview, |
105 | 117 | slice, |
| 118 | + generic_function, GenericMethod().method, max, |
| 119 | + dict.fromkeys, |
106 | 120 | defaultdict, deque, |
107 | 121 | SequenceMatcher, |
108 | 122 | dircmp, |
@@ -214,6 +228,26 @@ def test_no_chaining(self): |
214 | 228 | with self.assertRaises(TypeError): |
215 | 229 | t[int] |
216 | 230 |
|
| 231 | + class Dummy: |
| 232 | + pass |
| 233 | + |
| 234 | + def test_callable_alias_does_not_set_orig_class(self): |
| 235 | + dummy_type = self.Dummy |
| 236 | + |
| 237 | + def function[T](): |
| 238 | + result = dummy_type() |
| 239 | + result.__orig_class__ = str |
| 240 | + return result |
| 241 | + |
| 242 | + class Class: |
| 243 | + def method[T](self): |
| 244 | + result = dummy_type() |
| 245 | + result.__orig_class__ = str |
| 246 | + return result |
| 247 | + |
| 248 | + self.assertIs(function[int]().__orig_class__, str) |
| 249 | + self.assertIs(Class().method[int]().__orig_class__, str) |
| 250 | + |
217 | 251 | def test_generic_subclass(self): |
218 | 252 | class MyList(list): |
219 | 253 | pass |
|
0 commit comments