Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

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
hoefling committed Oct 13, 2019
commit 6e3523bc5658f06b40f1bbaf180c19d62d911e1d
12 changes: 6 additions & 6 deletions docs/source/additional_features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Copy link
Collaborator

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:

    bad = Application("Testing...", "with plugin")  # error: Argument 2 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:
Expand All @@ -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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, this is a bit long. Maybe leave out ("UnorderedPoint")?


Dataclasses can be generic and can be used in any other way a normal
class can be used:
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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
====================
Expand All @@ -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:
...

Expand Down