-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Selftype with TupleType #2436
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
Selftype with TupleType #2436
Conversation
So the real bug was not actually in #2408, but in my original implementation of selftype. |
Tested, no problems. I'll come back later with a review. |
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.
Just one question.
@@ -32,9 +32,9 @@ def analyze_member_access(name: str, | |||
is_operator: bool, | |||
builtin_type: Callable[[str], Instance], | |||
not_ready_callback: Callable[[str, Context], None], | |||
msg: MessageBuilder, | |||
msg: MessageBuilder, *, | |||
original_type: Type, |
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.
Now that you've made this mandatory and passed it explicitly everywhere, do you still need line 53 below? (original_type = original_type or typ
-- I can't put a comment there.)
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.
No, I was about to remove it
@@ -391,7 +391,7 @@ def f(x: Union[List[int], List[str], int]) -> None: | |||
else: | |||
x[0] # E: Value of type "int" is not indexable | |||
x + 1 | |||
x[0] # E: Value of type "int" is not indexable | |||
x[0] # E: Value of type "Union[List[int], List[str], int]" is not indexable |
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.
I'm guessing this is because of the better determination of original_type
right? I approve of the new error message.
(The last commit also makes some cosmetic changes) |
Thanks! This is a real improvement. |
BTW Can you write up some docs for self-type? I think it would be nice if we had some examples for this in mypy's chapter on generics. |
We are probably going to have a mypy release this week. It would be good to have the docs so that we can ask users to give it a spin. |
#2450. I am not confident with the examples, the phrasing, or the English grammar :| |
(Reopening #2408 after the revert #2414. This fixes parts of #2090)
This PR does three things:
original_type
recursively)_replace()
and_make()
return selftype, serving as test case for (1) and (2)As a consequence of (1), some error messages are changed, as exemplified in
check-isinstance.test
. I think it's better now, but if it isn't, perhaps we should separateoriginal_type
andreport_type
as discussed in #2193.