Commit cc24f5b
Support for functions producing generic functions (#3113)
Provides support for returning a generic Callable from a
function, allowing you to write a function that produces a
decorator, for example. This pattern is common:
```
def deco(x: int) -> Callable[[T], T]: ...
@Deco(4)
def f(stuff): ...
```
Details on why this touches so much code:
Returning a generic Callable from a function requires binding
type variables while we're traversing the type analysis phase of
the check. Previously, all type variable binding was done from
semanal.py. I refactored type variable tracking and binding into
its own class, that's used by both semanal.py and typeanal.py to
keep track of its type variables. I also, in the process, nixed
the thing where we're mutating TypeVarExprs to bind them, instead
keeping track of the bindings in the scope object I
created. Seems more sustainable in a world where more than one
class has to deal with typevar binding.1 parent c38a836 commit cc24f5b
File tree
7 files changed
+498
-355
lines changed- mypy
- test-data/unit
7 files changed
+498
-355
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
1623 | 1622 | | |
1624 | 1623 | | |
1625 | 1624 | | |
1626 | | - | |
| 1625 | + | |
1627 | 1626 | | |
1628 | 1627 | | |
1629 | 1628 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
| 42 | + | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | | - | |
| 68 | + | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
2211 | 2210 | | |
2212 | 2211 | | |
2213 | 2212 | | |
2214 | | - | |
2215 | | - | |
| 2213 | + | |
2216 | 2214 | | |
2217 | 2215 | | |
2218 | 2216 | | |
2219 | 2217 | | |
2220 | 2218 | | |
2221 | 2219 | | |
2222 | 2220 | | |
2223 | | - | |
2224 | | - | |
2225 | 2221 | | |
2226 | 2222 | | |
2227 | 2223 | | |
| |||
2237 | 2233 | | |
2238 | 2234 | | |
2239 | 2235 | | |
2240 | | - | |
2241 | 2236 | | |
2242 | 2237 | | |
2243 | 2238 | | |
2244 | 2239 | | |
2245 | 2240 | | |
2246 | | - | |
2247 | 2241 | | |
2248 | 2242 | | |
2249 | 2243 | | |
| |||
2287 | 2281 | | |
2288 | 2282 | | |
2289 | 2283 | | |
2290 | | - | |
2291 | | - | |
2292 | 2284 | | |
2293 | 2285 | | |
2294 | 2286 | | |
| |||
2323 | 2315 | | |
2324 | 2316 | | |
2325 | 2317 | | |
2326 | | - | |
2327 | | - | |
2328 | 2318 | | |
2329 | 2319 | | |
2330 | 2320 | | |
| |||
0 commit comments