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
Starting with version attrs 22.1.0, I started running into a type checking issue when running mypy. In particular, this occurs when calling asdict in parent class where that parent class does not use attrs but the child might.
This is a bit of an odd scenario so I'm not sure if the bug belongs here in attrs, mypy, or should just be an error. However, it did not produce any type checking errors using attrs 21.4.0.
Given that your asdict is protected by a has, I suspect that belongs into mypy because it's dynamic logic we can't express in attrs. But @Tinche might know more.
The problem is that we introduced an AttrsInstance Protocol. It looks like we forgot to add a newsfragment.
Activity
hynek commentedon Jul 29, 2022
Given that your asdict is protected by a
has, I suspect that belongs into mypy because it's dynamic logic we can't express in attrs. But @Tinche might know more.The problem is that we introduced an AttrsInstance Protocol. It looks like we forgot to add a newsfragment.
1oglop1 commentedon Aug 5, 2022
@hynek I notice that
AttrsInstanceis not imported inattrs.__init__.pyionly defined inattr.__init__.pyiis that intentional?hynek commentedon Aug 5, 2022
@Tinche did we just forget it?
Tinche commentedon Aug 5, 2022
Yeah I think so ;/
layday commentedon Aug 8, 2022
Probably worth nothing that
hasis a perfect match forTypeGuardfrom Python 3.10 (or its backport fromtyping-extensions). Inattrs/__init__.pyi:Elsewhere:
[...] if attr.has(type(self)): # `self` is now an `AttrsInstance` return attr.asdict(self) # Passes!But I suspect that
attrswould not want to depend ontyping-extensions.hynek commentedon Apr 3, 2023
fixed by #997
add attrs explicit dependency
add attrs explicit dependency (#10354)