Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use format_type for msg.type_not_iterable - #11490

Merged
JelleZijlstra merged 1 commit into
python:masterfrom
97littleleaf11:use-format-type-for-msg-iterable
Nov 10, 2021
Merged

Use format_type for msg.type_not_iterable#11490
JelleZijlstra merged 1 commit into
python:masterfrom
97littleleaf11:use-format-type-for-msg-iterable

Conversation

@97littleleaf11

Copy link
Copy Markdown
Collaborator

Description

Related #5072

Uses format_type to get a more concise output.

Comment thread mypy/messages.py
.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
Copy Markdown
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.

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

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 🙂

() = [] # E: can't assign to ()

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

@sobolevn sobolevn Nov 8, 2021

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

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
Copy Markdown
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
Copy Markdown
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