File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3- from itertools import product
43from typing import Callable
54
65from mypy import join
@@ -129,13 +128,16 @@ def narrow_declared_type(declared: Type, narrowed: Type) -> Type:
129128 if declared == narrowed :
130129 return original_declared
131130 if isinstance (declared , UnionType ):
131+ declared_items = declared .relevant_items ()
132+ if isinstance (narrowed , UnionType ):
133+ narrowed_items = narrowed .relevant_items ()
134+ else :
135+ narrowed_items = [narrowed ]
132136 return make_simplified_union (
133137 [
134138 narrow_declared_type (d , n )
135- for d , n in product (
136- declared .relevant_items (),
137- narrowed .relevant_items () if isinstance (narrowed , UnionType ) else (narrowed ,),
138- )
139+ for d in declared_items
140+ for n in narrowed_items
139141 # This (ugly) special-casing is needed to support checking
140142 # branches like this:
141143 # x: Union[float, complex]
You can’t perform that action at this time.
0 commit comments