Repository navigation
Type alias expansion sometimes interferes with type variable binding #3924
Description
Activity
- addedbugmypy got something wrongmypy got something wrong
on Sep 6, 2017 Sounds like the code that made
-> Callable[[T], T]possible in the first place still has some bugs...I have an issue which is, I believe, related to this:
from typing import TypeVar, Callable T = TypeVar("T") Function = Callable[[T], T] a: Function = ... b: Function[T] = ... c: Callable[[T], T] = ...
(save as
test.pyi, or replace the ellipsis withlambda x: x, function created in function etc.)Mypy always disallows
a, with--strictdisallowsband always allowsc. Tested with 0.800 and0.810+dev.9e0e23e97653dab3a558d34340486e7a66f7d6f0.How much is this related, should I file a separate issue? I would expect either
aorb(no idea which one though) to be entirely correctWhen I was looking for duplicates, #8922 also looked related
- added a commit that references this issue
on Jul 6, 2021 - addedtopic-callsFunction calls, *args, **kwargs, defaultsFunction calls, *args, **kwargs, defaultstopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues
on Apr 4, 2022 I just closed #8273 as a duplicate of this issue, but there was some interesting discussion about possible causes and solutions in that issue.
- added a commit that references this issue
on May 18, 2023 Coming at this from #13449, where there's some discussion of my case (slightly different from the OP there), I have a question:
Is there a benefit or meaning to allowing
<nothing>as a type inference? I'm wondering what the potential benefit and harm would be of making--strictenable rejection of any inference which produces<nothing>as an error.The only instances of
<nothing>which I've seen are avoidable errors related to scoping of type variables. Are there use-cases in which it is the right type to infer and matches the user's intent?<nothing>is a subtype of all types, a.k.a. bottom type, a.k.a. error type, a.k.a. item type of empty collection. It behaves as it is for various reasons (both good and bad). What you are asking about is not related to this issue. If you can clearly describe what exactly do you want (with examples), you can open a new issue.- added a commit that references this issue
on Oct 23, 2024 Any update on this? This is interfering with django ninja api decorator type hints (getting the following error: error: Untyped decorator makes function) when defining endpoints as:
router:: Router = Router() @router.get( "endpoint", response={ 200: SomeModel, 400: Error, 401: Error, 404: Error, 500: Error, }, ) def some_endpoint(request: HttpRequest -> SomeModel: pass
- added a commit that references this issue
on Dec 21, 2025
Consider the following two examples, I think they should be equivalent, since logically expansion of type aliases should happen before any other steps. (At least this would be consistent and natural for those familiar with C macros):
Here
test1works as expected, while if I use an alias something strange happens withtest2. Namely notice a subtle difference between their types.I have noticed few similar scenarios, they all seem to be related to
Callable.