-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow better tuple
type aliases, fix "Type application" error
#12134
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Could you also add a test for type alias my_tuple = tuple; my_tuple[int, float]
and for use of cast
?
Also IIRC python eval actually runs code with the python interpreter. Would it make more sense for this to be in check-python310.test?
This comment has been minimized.
This comment has been minimized.
How is that related? 🤔
|
Uh, that looks like python/typeshed#7019... Maybe syncing typeshed again might help?? |
I think that we should fix it instead of just hiding. I am looking into it 🙂 |
It happens here: Lines 274 to 275 in 48dc990
|
I reduced from typing import Any
_HeaderType = Any
class Message:
def __getitem__(self, name: str) -> _HeaderType: ... And it still happens. |
It took me literally two hours of debugging. I was able to reproduce this problem only in my newly written test. That's it. Nothing else worked. Somehow I figured it out (at least I hope so). |
Fantastic work - well done! But, bizarre that mypy suddenly started reporting this error recently, after it was fine with this line for so long 🤯 |
Thanks, but I still have to fix |
This comment has been minimized.
This comment has been minimized.
mypy_primer seemed to find a similar issue: https://github.com/aio-libs/aiohttp/blob/f78c128f52f4f7e55ebaa8ed0aa764031e98dfe8/aiohttp/web.py#L283 |
Ok, here's what is going on. We have a correct test failure:
Why? Because Right now I skip this step, that's why the test fails. But, Should it be What |
@erictraut any thoughts on this? It looks like pyright handles this kind of thing much better than mypy at the moment — would be great to get your advice, if you've got the time :) |
Sorry @AlexWaygood, I missed your earlier question. I'm not clear on which case you're referring to in your question, but I'll attempt to answer and you can tell me if I misinterpreted your question. For non-tuple generic classes, pyright maintains a fixed-size list of type arguments once the class is specialized. the length of this list is determined by the fixed number of type parameters in the generic class. For tuples, pyright maintains a separate (variable-sized) list of type arguments. This is in addition to the fixed-sized list, which corresponds to the type argument for the For the variable-sized tuple type argument list, pyright also records (for each entry) whether the type has a corresponding I hope that helps. |
1 similar comment
@JukkaL sorry, I am not very active right now. I have time to read the inbox, but I don't have much time to actually write code 😢 I hope I will be able to solve all the things in 1-2 months. |
Diff from mypy_primer, showing the effect of this PR on open source code: aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/web.py:283: error: Unused "type: ignore[assignment]" comment
|
@sobolevn I'd love to have this fix included in 1.0. If you are busy, I can look into finishing this. |
@JukkaL I would totally appreciate some help on this issue! 👍 |
I created #14184 as an updated version of this PR. |
Fix type aliases like these: ``` T = tuple[int, str] ``` Type applications involving fixed-length tuples still don't fully work. The inferred type is a variable-length tuple when constructing a tuple using a type application, e.g. `tuple[int, str]((1, ""))`. This seems a pretty low-priority issue, whereas the type alias use case seems common. Most of the work was by @sobolevn originally in #12134. I just finished it up. Fixes #11098.
I am also testing how new
mypy_primer
andmypy_comment
actions work: #12125I expect "No change" comment to appear.
Closes #11098