@@ -346,15 +346,32 @@ fn1: Union[Callable[[int], int], Callable[[int], int]]
346
346
reveal_type(functools.partial(fn1, 2)()) # N: Revealed type is "builtins.int"
347
347
348
348
fn2: Union[Callable[[int], int], Callable[[int], str]]
349
- reveal_type(functools.partial(fn2, 2)()) # N: Revealed type is "builtins.object "
349
+ reveal_type(functools.partial(fn2, 2)()) # N: Revealed type is "Union[ builtins.int, builtins.str] "
350
350
351
351
fn3: Union[Callable[[int], int], str]
352
352
reveal_type(functools.partial(fn3, 2)()) # E: "str" not callable \
353
- # E: "Union[Callable[[int], int], str]" not callable \
354
353
# N: Revealed type is "builtins.int" \
355
354
# E: Argument 1 to "partial" has incompatible type "Union[Callable[[int], int], str]"; expected "Callable[..., int]"
356
355
[builtins fixtures/tuple.pyi]
357
356
357
+ [case testFunctoolsPartialUnionOfTypeAndCallable]
358
+ import functools
359
+ from typing import Callable, Union, Type
360
+ from typing_extensions import TypeAlias
361
+
362
+ class FooBar:
363
+ def __init__(self, arg1: str) -> None:
364
+ pass
365
+
366
+ def f1(t: Union[Type[FooBar], Callable[..., 'FooBar']]) -> None:
367
+ val = functools.partial(t)
368
+
369
+ FooBarFunc: TypeAlias = Callable[..., 'FooBar']
370
+
371
+ def f2(t: Union[Type[FooBar], FooBarFunc]) -> None:
372
+ val = functools.partial(t)
373
+ [builtins fixtures/tuple.pyi]
374
+
358
375
[case testFunctoolsPartialExplicitType]
359
376
from functools import partial
360
377
from typing import Type, TypeVar, Callable
0 commit comments