Skip to content

Use format_type for msg.type_not_iterable #11490

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

Merged

Conversation

97littleleaf11
Copy link
Collaborator

Description

Related #5072

Uses format_type to get a more concise output.

notes.append('Expression tuple item {} has type "{}"; "{}" expected; '
.format(str(i), format_type_bare(rhs_t), format_type_bare(lhs_t)))
notes.append('Expression tuple item {} has type {}; {} expected; '
.format(str(i), format_type(rhs_t), format_type(lhs_t)))
error_cnt += 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing from format_type_bare to format_type to keep consistency with other usage of format_type.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have a couple of questions 🙂

@@ -1468,7 +1468,7 @@ x9, y9, x10, y10, z5 = *points2, 1, *points2 # E: Contiguous iterable with same
() = [] # E: can't assign to ()

[case testAssignEmptyBogus]
() = 1 # E: "Literal[1]?" object is not iterable
Copy link
Member

@sobolevn sobolevn Nov 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a significant change and I don't think that is an improvement. Literal[1] is more specific, I personally like it more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this is an interesting case. I think it's a different issue that we might need to modify the format_type.

@@ -556,7 +556,7 @@ reveal_type(d1) # N: Revealed type is "Union[Any, builtins.float]"
reveal_type(d2) # N: Revealed type is "Union[Any, builtins.float]"

e: Union[Any, Tuple[float, float], int]
(e1, e2) = e # E: "builtins.int" object is not iterable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of places where builtins. is used, and some places where it is not used. I cannot tell what kind of principle is used here 😞

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy keeps the prefix in reveal_type for more verbose information. And according to the original discussion, it's better to discard builtins. to get concise error messages. Also, cpython dosen't output builtins. when error occurs.

@JelleZijlstra JelleZijlstra merged commit dde8fd8 into python:master Nov 10, 2021
@97littleleaf11 97littleleaf11 deleted the use-format-type-for-msg-iterable branch November 10, 2021 16:10
JukkaL pushed a commit that referenced this pull request Nov 11, 2021
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants