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
I'm working on the mypy plugin but I am gonna need to know the final answer on how "hybrid" mode wants to work if there are both annotations and attribs. I think the options are:
Take only the ones that have = attr.ib()
Take only the annotated ones.
Take both.
Raise an exception.
Hmm. I thought #3 would be easy to implement (just don't raise the error) but it turns out we can't tell the order between annotated and un-annotated attributes.
class A:
x: int
y = attr.ib()
cls.__annotations__ -> [x]
cls.__dict__.keys(). -> [y]
But which is actually first?
#2 is kind of a weird one. Why throw away those attr.ib()s? #1 is relatively easy to implement. Because it's just a try catch. #4 Might require the user to add ClassVar in order to add it.
Oh I should note that I think this should still be fine:
@define
class A:
x: int = field()
y = field()
We shouldn't force you to have to annotate everything.
Hmm. That might make 4 harder to implement. :)
The text was updated successfully, but these errors were encountered:
Given your explanations and my older experiments I think only 1 and 4 are feasible.
But given your example, 4 seems also more trouble and edge cases than necessary?
I kinda still feel that the sharp edges of the hybrid approach are the best trade off because it's almost impossible to get a silent failure in a real-world project. Sure maybe you get confused the first time you get missing attributes but is it worth to force people pass arguments everywhere for it? 🤔 (skip time 1 year ahead: Hynek hates himself for this thinking 🤪)
(I'm keeping this open as long as the NG APIs are provisional, but I've mostly made up my mind. I'm happy to change it if substantial user complaints come in.)
Originally posted by @euresti in #668 (comment)
I'm working on the mypy plugin but I am gonna need to know the final answer on how "hybrid" mode wants to work if there are both annotations and attribs. I think the options are:
= attr.ib()
Hmm. I thought #3 would be easy to implement (just don't raise the error) but it turns out we can't tell the order between annotated and un-annotated attributes.
But which is actually first?
#2 is kind of a weird one. Why throw away those attr.ib()s?
#1 is relatively easy to implement. Because it's just a try catch.
#4 Might require the user to add
ClassVar
in order to add it.Oh I should note that I think this should still be fine:
We shouldn't force you to have to annotate everything.
Hmm. That might make 4 harder to implement. :)
The text was updated successfully, but these errors were encountered: