Uh oh!
There was an error while loading. Please reload this page.
Allow better tuple type aliases, fix "Type application" error - #12134
Allow better tuple type aliases, fix "Type application" error#12134sobolevn wants to merge 3 commits into
tuple type aliases, fix "Type application" error#12134Conversation
hauntsaninja
left a comment
There was a problem hiding this comment.
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.
sobolevn
commented
Feb 6, 2022
How is that related? 🤔 |
AlexWaygood
commented
Feb 6, 2022
Uh, that looks like python/typeshed#7019... Maybe syncing typeshed again might help?? |
sobolevn
commented
Feb 6, 2022
I think that we should fix it instead of just hiding. I am looking into it 🙂 |
sobolevn
commented
Feb 6, 2022
It happens here: Lines 274 to 275 in 48dc990 |
sobolevn
commented
Feb 6, 2022
I reduced fromtypingimportAny_HeaderType=AnyclassMessage:
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). |
AlexWaygood
commented
Feb 6, 2022
Fantastic work - well done! But, bizarre that mypy suddenly started reporting this error recently, after it was fine with this line for so long 🤯 |
sobolevn
commented
Feb 6, 2022
Thanks, but I still have to fix |
This comment has been minimized.
This comment has been minimized.
sobolevn
commented
Feb 6, 2022
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 |
AlexWaygood
commented
Feb 13, 2022
@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. |
JukkaL
commented
Apr 14, 2022
1 similar comment
JukkaL
commented
Apr 14, 2022
sobolevn
commented
Apr 14, 2022
@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 |
JukkaL
commented
Nov 4, 2022
@sobolevn I'd love to have this fix included in 1.0. If you are busy, I can look into finishing this. |
sobolevn
commented
Nov 4, 2022
@JukkaL I would totally appreciate some help on this issue! 👍 |
JukkaL
commented
Nov 25, 2022
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_primerandmypy_commentactions work: #12125I expect "No change" comment to appear.
Closes#11098