| 1 |
import typing |
| 2 |
from typing import ( |
| 3 |
Callable, |
| 4 |
Dict, |
| 5 |
Generic, |
| 6 |
List, |
| 7 |
Sequence, |
| 8 |
Tuple, |
| 9 |
Type, |
| 10 |
TypeVar, |
| 11 |
) |
| 12 |
|
| 13 |
T = TypeVar('T') |
| 14 |
|
| 15 |
|
| 16 |
def foo(x: T) -> T: |
| 17 |
return x |
| 18 |
|
| 19 |
|
| 20 |
class CustomGeneric(Generic[T]): |
| 21 |
def __init__(self, val: T) -> None: |
| 22 |
self.val = val |
| 23 |
|
| 24 |
|
| 25 |
class PlainClass(object): |
| 26 |
pass |
| 27 |
|
| 28 |
|
| 29 |
tpl = ("1", 2) |
| 30 |
tpl_typed: Tuple[str, int] = ("2", 3) |
| 31 |
|
| 32 |
collection = {"a": 1} |
| 33 |
collection_typed: Dict[str, int] = {"a": 1} |
| 34 |
|
| 35 |
list_of_ints: List[int] = [42] |
| 36 |
list_of_funcs: List[Callable[[T], T]] = [foo] |
| 37 |
|
| 38 |
custom_generic = CustomGeneric(123.45) |
| 39 |
|
| 40 |
plain_instance = PlainClass() |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
def list_t_to_list_t(the_list: List[T]) -> List[T]: |
| 45 |
return the_list |
| 46 |
|
| 47 |
x0 = list_t_to_list_t("abc")[0] |
| 48 |
|
| 49 |
x0 |
| 50 |
|
| 51 |
x1 = list_t_to_list_t(foo)[0] |
| 52 |
|
| 53 |
x1 |
| 54 |
|
| 55 |
x1 = list_t_to_list_t(typing)[0] |
| 56 |
|
| 57 |
x1 |
| 58 |
|
| 59 |
x2 = list_t_to_list_t(tpl)[0] |
| 60 |
|
| 61 |
x2 |
| 62 |
|
| 63 |
x3 = list_t_to_list_t(tpl_typed)[0] |
| 64 |
|
| 65 |
x3 |
| 66 |
|
| 67 |
x4 = list_t_to_list_t(collection)[0] |
| 68 |
|
| 69 |
x4 |
| 70 |
|
| 71 |
x5 = list_t_to_list_t(collection_typed)[0] |
| 72 |
|
| 73 |
x5 |
| 74 |
|
| 75 |
x6 = list_t_to_list_t(custom_generic)[0] |
| 76 |
|
| 77 |
x6 |
| 78 |
|
| 79 |
x7 = list_t_to_list_t(plain_instance)[0] |
| 80 |
|
| 81 |
x7 |
| 82 |
|
| 83 |
for a in list_t_to_list_t(12): |
| 84 |
|
| 85 |
a |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
def list_type_t_to_list_t(the_list: List[Type[T]]) -> List[T]: |
| 90 |
return [x() for x in the_list] |
| 91 |
|
| 92 |
x0 = list_type_t_to_list_t("abc")[0] |
| 93 |
|
| 94 |
x0 |
| 95 |
|
| 96 |
x1 = list_type_t_to_list_t(foo)[0] |
| 97 |
|
| 98 |
x1 |
| 99 |
|
| 100 |
x2 = list_type_t_to_list_t(tpl)[0] |
| 101 |
|
| 102 |
x2 |
| 103 |
|
| 104 |
x3 = list_type_t_to_list_t(tpl_typed)[0] |
| 105 |
|
| 106 |
x3 |
| 107 |
|
| 108 |
x4 = list_type_t_to_list_t(collection)[0] |
| 109 |
|
| 110 |
x4 |
| 111 |
|
| 112 |
x5 = list_type_t_to_list_t(collection_typed)[0] |
| 113 |
|
| 114 |
x5 |
| 115 |
|
| 116 |
x6 = list_type_t_to_list_t(custom_generic)[0] |
| 117 |
|
| 118 |
x6 |
| 119 |
|
| 120 |
x7 = list_type_t_to_list_t(plain_instance)[0] |
| 121 |
|
| 122 |
x7 |
| 123 |
|
| 124 |
for a in list_type_t_to_list_t(12): |
| 125 |
|
| 126 |
a |
| 127 |
|
| 128 |
|
| 129 |
x0 = list_type_t_to_list_t(["abc"])[0] |
| 130 |
|
| 131 |
x0 |
| 132 |
|
| 133 |
x1 = list_type_t_to_list_t([foo])[0] |
| 134 |
|
| 135 |
x1 |
| 136 |
|
| 137 |
x2 = list_type_t_to_list_t([tpl])[0] |
| 138 |
|
| 139 |
x2 |
| 140 |
|
| 141 |
x3 = list_type_t_to_list_t([tpl_typed])[0] |
| 142 |
|
| 143 |
x3 |
| 144 |
|
| 145 |
x4 = list_type_t_to_list_t([collection])[0] |
| 146 |
|
| 147 |
x4 |
| 148 |
|
| 149 |
x5 = list_type_t_to_list_t([collection_typed])[0] |
| 150 |
|
| 151 |
x5 |
| 152 |
|
| 153 |
x6 = list_type_t_to_list_t([custom_generic])[0] |
| 154 |
|
| 155 |
x6 |
| 156 |
|
| 157 |
x7 = list_type_t_to_list_t([plain_instance])[0] |
| 158 |
|
| 159 |
x7 |
| 160 |
|
| 161 |
for a in list_type_t_to_list_t([12]): |
| 162 |
|
| 163 |
a |
| 164 |
|
| 165 |
|
| 166 |
def list_func_t_to_list_t(the_list: List[Callable[[T], T]]) -> List[T]: |
| 167 |
|
| 168 |
|
| 169 |
pass |
| 170 |
|
| 171 |
|
| 172 |
x0 = list_func_t_to_list_t("abc")[0] |
| 173 |
|
| 174 |
x0 |
| 175 |
|
| 176 |
x1 = list_func_t_to_list_t(foo)[0] |
| 177 |
|
| 178 |
x1 |
| 179 |
|
| 180 |
x2 = list_func_t_to_list_t(tpl)[0] |
| 181 |
|
| 182 |
x2 |
| 183 |
|
| 184 |
x3 = list_func_t_to_list_t(tpl_typed)[0] |
| 185 |
|
| 186 |
x3 |
| 187 |
|
| 188 |
x4 = list_func_t_to_list_t(collection)[0] |
| 189 |
|
| 190 |
x4 |
| 191 |
|
| 192 |
x5 = list_func_t_to_list_t(collection_typed)[0] |
| 193 |
|
| 194 |
x5 |
| 195 |
|
| 196 |
x6 = list_func_t_to_list_t(custom_generic)[0] |
| 197 |
|
| 198 |
x6 |
| 199 |
|
| 200 |
x7 = list_func_t_to_list_t(plain_instance)[0] |
| 201 |
|
| 202 |
x7 |
| 203 |
|
| 204 |
for a in list_func_t_to_list_t(12): |
| 205 |
|
| 206 |
a |
| 207 |
|
| 208 |
|
| 209 |
x0 = list_func_t_to_list_t(["abc"])[0] |
| 210 |
|
| 211 |
x0 |
| 212 |
|
| 213 |
x2 = list_func_t_to_list_t([tpl])[0] |
| 214 |
|
| 215 |
x2 |
| 216 |
|
| 217 |
x3 = list_func_t_to_list_t([tpl_typed])[0] |
| 218 |
|
| 219 |
x3 |
| 220 |
|
| 221 |
x4 = list_func_t_to_list_t([collection])[0] |
| 222 |
|
| 223 |
x4 |
| 224 |
|
| 225 |
x5 = list_func_t_to_list_t([collection_typed])[0] |
| 226 |
|
| 227 |
x5 |
| 228 |
|
| 229 |
x6 = list_func_t_to_list_t([custom_generic])[0] |
| 230 |
|
| 231 |
x6 |
| 232 |
|
| 233 |
x7 = list_func_t_to_list_t([plain_instance])[0] |
| 234 |
|
| 235 |
x7 |
| 236 |
|
| 237 |
for a in list_func_t_to_list_t([12]): |
| 238 |
|
| 239 |
a |
| 240 |
|
| 241 |
|
| 242 |
def tuple_t(tuple_in: Tuple[T]]) -> Sequence[T]: |
| 243 |
return tuple_in |
| 244 |
|
| 245 |
|
| 246 |
x0 = list_t_to_list_t("abc")[0] |
| 247 |
|
| 248 |
x0 |
| 249 |
|
| 250 |
x1 = list_t_to_list_t(foo)[0] |
| 251 |
|
| 252 |
x1 |
| 253 |
|
| 254 |
x2 = list_t_to_list_t(tpl)[0] |
| 255 |
|
| 256 |
x2 |
| 257 |
|
| 258 |
x3 = list_t_to_list_t(tpl_typed)[0] |
| 259 |
|
| 260 |
x3 |
| 261 |
|
| 262 |
x4 = list_t_to_list_t(collection)[0] |
| 263 |
|
| 264 |
x4 |
| 265 |
|
| 266 |
x5 = list_t_to_list_t(collection_typed)[0] |
| 267 |
|
| 268 |
x5 |
| 269 |
|
| 270 |
x6 = list_t_to_list_t(custom_generic)[0] |
| 271 |
|
| 272 |
x6 |
| 273 |
|
| 274 |
x7 = list_t_to_list_t(plain_instance)[0] |
| 275 |
|
| 276 |
x7 |
| 277 |
|
| 278 |
for a in list_t_to_list_t(12): |
| 279 |
|
| 280 |
a |
| 281 |
|
| 282 |
|
| 283 |
def tuple_t_elipsis(tuple_in: Tuple[T, ...]]) -> Sequence[T]: |
| 284 |
return tuple_in |
| 285 |
|
| 286 |
|
| 287 |
x0 = list_t_to_list_t("abc")[0] |
| 288 |
|
| 289 |
x0 |
| 290 |
|
| 291 |
x1 = list_t_to_list_t(foo)[0] |
| 292 |
|
| 293 |
x1 |
| 294 |
|
| 295 |
x2 = list_t_to_list_t(tpl)[0] |
| 296 |
|
| 297 |
x2 |
| 298 |
|
| 299 |
x3 = list_t_to_list_t(tpl_typed)[0] |
| 300 |
|
| 301 |
x3 |
| 302 |
|
| 303 |
x4 = list_t_to_list_t(collection)[0] |
| 304 |
|
| 305 |
x4 |
| 306 |
|
| 307 |
x5 = list_t_to_list_t(collection_typed)[0] |
| 308 |
|
| 309 |
x5 |
| 310 |
|
| 311 |
x6 = list_t_to_list_t(custom_generic)[0] |
| 312 |
|
| 313 |
x6 |
| 314 |
|
| 315 |
x7 = list_t_to_list_t(plain_instance)[0] |
| 316 |
|
| 317 |
x7 |
| 318 |
|
| 319 |
for a in list_t_to_list_t(12): |
| 320 |
|
| 321 |
a |
| 322 |
|
| 323 |
|
| 324 |
def list_tuple_t_to_tuple_list_t(the_list: List[Tuple[T]]) -> Tuple[List[T], ...]: |
| 325 |
return tuple(list(x) for x in the_list) |
| 326 |
|
| 327 |
|
| 328 |
for b in list_tuple_t_to_tuple_list_t(list_of_ints): |
| 329 |
|
| 330 |
b[0] |
| 331 |
|
| 332 |
|
| 333 |
def list_tuple_t_elipsis_to_tuple_list_t(the_list: List[Tuple[T, ...]]) -> Tuple[List[T], ...]: |
| 334 |
return tuple(list(x) for x in the_list) |
| 335 |
|
| 336 |
|
| 337 |
for b in list_tuple_t_to_tuple_list_t(list_of_ints): |
| 338 |
|
| 339 |
b[0] |