Commit f650315
committed
fix: isinstance narrowing regression with dynamic tuple argument
When isinstance is called with a dynamically-computed tuple of types
(e.g. isinstance(exc, tuple(expected_excs))), the second argument's
stored type gets widened to match the _ClassInfo recursive type alias
(type | types.UnionType | tuple[_ClassInfo, ...]). The union handler
in get_type_range_of_type then decomposes this into individual members,
producing TypeRange(object, ...) from bare 'type', which incorrectly
narrows the expression to 'object' instead of keeping its existing type.
Fix by checking if the simplified union result is just 'object' — which
indicates we've lost type precision — and returning None to fall back to
keeping the current type, matching the v1.19 behavior.
Also handle None sub-items explicitly (propagate uncertainty) and filter
out UninhabitedType entries before simplifying.
Fixes #21181
Signed-off-by: bahtya <bahtyar153@qq.com>1 parent bb05513 commit f650315
1 file changed
+11
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8028 | 8028 | | |
8029 | 8029 | | |
8030 | 8030 | | |
8031 | | - | |
| 8031 | + | |
| 8032 | + | |
| 8033 | + | |
| 8034 | + | |
| 8035 | + | |
| 8036 | + | |
| 8037 | + | |
| 8038 | + | |
| 8039 | + | |
| 8040 | + | |
| 8041 | + | |
8032 | 8042 | | |
8033 | 8043 | | |
8034 | 8044 | | |
| |||
0 commit comments