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
This is just an idea. Some users of a library I work on use static analysis and other users don't, so we use both type hinting and validation on the attributes. We have several classes like this:
@rgabbard pointed out to me that some types cannot be fully instance-checked, e.g. all subscripted generics from typing, like List[int]. So auto_attribs_with_validation could do a few things:
Option A: Error out at class definition if there are any un-checkable types
Option B: Strip the subscripts off the generics, so
This is just an idea. Some users of a library I work on use static analysis and other users don't, so we use both type hinting and validation on the attributes. We have several classes like this:
And in this search you can see that most users of
instance_of
stick it on every attribute when they use it at all.It would be nice if
attrs
had a kwarg likeauto_attribs_with_validation
that would convert the below class to the above class:Then of course if you executed
c = C("foo", "bar", "baz")
you would get aTypeError
.I'm aware that it may not be worth adding another kwarg to attrs.
If this is a good idea, then I can probably write the PR.
The text was updated successfully, but these errors were encountered: