You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import typing
import attr
@attr.s(frozen=True, auto_attribs=True, kw_only=True)
class Position:
line: int
column: int
@attr.s(frozen=True, auto_attribs=True, kw_only=True)
class Node:
start: typing.Optional[Position] = None
end: typing.Optional[Position] = None
@attr.s(frozen=True, auto_attribs=True, kw_only=True)
class Operator(Node):
symbol: str
name: str
precedence: int
associativity: str # "left" or "right"
It gives following errors:
f.py:21: error: Non-default attributes not allowed after default attributes.
f.py:22: error: Non-default attributes not allowed after default attributes.
f.py:23: error: Non-default attributes not allowed after default attributes.
f.py:24: error: Non-default attributes not allowed after default attributes.
If I understand correctly, mypy doesn't consider the existence of a new kw_only=True .
@euresti
thanks for the mypy plugin!
The latest Pycharm 2018.3.2 still does not like kw_only. Inspection throws an error on the decorator line and whenever an object is created:
Activity
euresti commentedon Dec 16, 2018
Hmm. This feature definitely didn't exist when I wrote the plugin. Maybe I'll have time over the break to work on this.
quinor commentedon Dec 16, 2018
From my understanding it makes mypy unusable with attrs right now, or is there a workaround that doesn't require too much code?
euresti commentedon Dec 17, 2018
Sadly, for now the only way around it is to
# type: ignorethose lines.hynek commentedon Dec 18, 2018
This should be a bug on the mypy tracker no?
dmfigol commentedon Jan 8, 2019
@euresti
thanks for the mypy plugin!
The latest Pycharm 2018.3.2 still does not like
kw_only. Inspection throws an error on the decorator line and whenever an object is created:@attr.s(auto_attribs=True, repr=False, kw_only=True)Pycharm inspection:
Car(name="Lotus", year=2001) # object created with attrs + kw_onlyPycharm inspection:
Unexpected argument(s). Possible callees: object(self: object) object.__new__(cls: object)It seems that attrs stub in typeshed is missing
kw_only?.../typeshed/third_party/2and3/attr/__init__.pyiUPDATE: it seems it is already fixed in the typeshed. I didn't notice, sorry
euresti commentedon Jan 9, 2019
Fixed here:
python/typeshed#2720
And here:
python/mypy#6107