-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Update mypy error messages in code examples, part 1 #7706
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
Closed
hoefling
wants to merge
5
commits into
python:master
from
hoefling:code-examples-mypy-error-messages-1
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e3523b
revisited mypy error messages in additional_features.rst
hoefling 5b23ebd
revisited mypy error messages in casts.rst
hoefling 49f5059
revisited mypy error messages in class_basics.rst
hoefling bd24079
revisited mypy error messages in common_issues.rst
hoefling f542adb
changed code example where mypy reports incompatible types
hoefling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
revisited mypy error messages in additional_features.rst
Signed-off-by: Oleg Höfling <[email protected]>
- Loading branch information
commit 6e3523bc5658f06b40f1bbaf180c19d62d911e1d
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ They can be defined using the :py:func:`@dataclasses.dataclass | |
| plugins: List[str] = field(default_factory=list) | ||
|
|
||
| test = Application("Testing...") # OK | ||
| bad = Application("Testing...", "with plugin") # Error: List[str] expected | ||
| bad = Application("Testing...", "with plugin") # error: Argument 2 to "Application" has incompatible type "str"; expected "List[str]" | ||
|
|
||
| Mypy will detect special methods (such as :py:meth:`__lt__ <object.__lt__>`) depending on the flags used to | ||
| define dataclasses. For example: | ||
|
|
@@ -44,7 +44,7 @@ define dataclasses. For example: | |
| y: int | ||
|
|
||
| OrderedPoint(1, 2) < OrderedPoint(3, 4) # OK | ||
| UnorderedPoint(1, 2) < UnorderedPoint(3, 4) # Error: Unsupported operand types | ||
| UnorderedPoint(1, 2) < UnorderedPoint(3, 4) # error: Unsupported left operand type for < ("UnorderedPoint") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this is a bit long. Maybe leave out |
||
|
|
||
| Dataclasses can be generic and can be used in any other way a normal | ||
| class can be used: | ||
|
|
@@ -103,8 +103,8 @@ do **not** work: | |
| """ | ||
| attribute: int | ||
|
|
||
| AliasDecorated(attribute=1) # error: Unexpected keyword argument | ||
| DynamicallyDecorated(attribute=1) # error: Unexpected keyword argument | ||
| AliasDecorated(attribute=1) # error: Unexpected keyword argument "attribute" for "AliasDecorated" | ||
| DynamicallyDecorated(attribute=1) # error: Unexpected keyword argument "attribute" for "DynamicallyDecorated" | ||
|
|
||
| .. _attrs_package: | ||
|
|
||
|
|
@@ -153,7 +153,7 @@ That enables this to work: | |
| class A: | ||
| one: int = attr.ib(8) | ||
| two: Dict[str, str] = attr.Factory(dict) | ||
| bad: str = attr.ib(16) # Error: can't assign int to str | ||
| bad: str = attr.ib(16) # error: Incompatible types in assignment (expression has type "int", variable has type "str") | ||
|
|
||
| Caveats/Known Issues | ||
| ==================== | ||
|
|
@@ -169,7 +169,7 @@ Caveats/Known Issues | |
|
|
||
| import attr | ||
| YES = True | ||
| @attr.s(init=YES) | ||
| @attr.s(init=YES) # error: "init" argument must be True or False. | ||
| class A: | ||
| ... | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'd try to keep lines a bit shorter to avoid horizontal scrolling in most cases. Maybe keep them under 100 characters? I think that it's fine to shorten messages. For example leaving out
to "Application"above seems reasonable. Also, it would be fine to split he comment into multiple lines. Maybe like this: