Commit d262121
committed
fix: handle union-bound TypeVar in type[T] callable analysis
When a TypeVar T has a union bound (e.g. T: bool|int|float|str),
calling a value of type type[T] would incorrectly infer the return
type as the union rather than T. This happened because
analyze_type_type_callee only replaced return types for CallableType
and Overloaded, not for UnionType.
Additionally, CallableType.type_object() would crash with an assertion
error when encountering a TypeVarType whose upper_bound is a union,
since it expected all paths to resolve to an Instance.
Fixes #21106
Signed-off-by: bahtya <bahtyar153@qq.com>1 parent bb05513 commit d262121
2 files changed
+26
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1900 | 1900 | | |
1901 | 1901 | | |
1902 | 1902 | | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
1903 | 1912 | | |
1904 | 1913 | | |
1905 | 1914 | | |
| |||
1936 | 1945 | | |
1937 | 1946 | | |
1938 | 1947 | | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
1939 | 1956 | | |
1940 | 1957 | | |
1941 | 1958 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2311 | 2311 | | |
2312 | 2312 | | |
2313 | 2313 | | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
2314 | 2323 | | |
2315 | 2324 | | |
2316 | 2325 | | |
| |||
0 commit comments