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
Builders should be remade to not use properties and instead they should just accept direct mutation using their attributes. Setters or properties which are not directly built may remain but they shouldn't be the main way to use the builder.
Why is this needed?
Currently, you are required to use long builders using fairly unpythonic setters instead of just being able to set everything in the __init__. Normally this would've been possible thanks to attrs but since the properties are prefixed with underscores pyright cannot understand that attrs is fine with the underscores being left out.
Ideal implementation
# beforeclassSomeBuilder:
_whatever: module.SomeEnum_something: int=attr.field(kw_only=True)
_other: str=attr.field(kw_only=True)
@propertydefwhatever(self) ->module.SomeEnum:
returnself._whatever# <repeated for all other fields>defset_whatever(self: T, x: Union[int, module.SomeEnum]) ->T:
self._whatever=module.SomeEnum(x)
returnself# <repeated for all other fields>
# afterclassSomeBuilder:
whatever: module.SomeEnumsomething: int=attr.field(kw_only=True)
other: str=attr.field(kw_only=True)
defset_whatever(self: T, x: Union[int, module.SomeEnum]) ->T:
self.whatever=module.SomeEnum(x)
returnself# <repeated for all other fields>
Checklist
I have searched the issue tracker and have made sure it's not a duplicate. If it is a follow up of another issue, I have specified it.
The text was updated successfully, but these errors were encountered:
Builders should be remade to not use properties and instead they should just accept direct mutation using their attributes.
This would prevent the library from adding validation to setting calls in the future which isn't ideal seeing as the rest flow needs a lot of validation.
Also how the data is stored internally is impl detail, this pattern you're suggesting would make the internal storage a part of the interface which would change the nature of builders such as the button builder.
Normally this would've been possible thanks to attrs but since the properties are prefixed with underscores pyright cannot understand that attrs is fine with the underscores being left out.
That's a pyright/attrs issue and not in scope of this project, you shouldn't let a type checker stop you from doing stuff just because its wrong. You can just pass data to the init if you want to avoid any validation or don't want to use setters
Summary
Builders should be remade to not use properties and instead they should just accept direct mutation using their attributes. Setters or properties which are not directly built may remain but they shouldn't be the main way to use the builder.
Why is this needed?
Currently, you are required to use long builders using fairly unpythonic setters instead of just being able to set everything in the
__init__
. Normally this would've been possible thanks to attrs but since the properties are prefixed with underscores pyright cannot understand that attrs is fine with the underscores being left out.Ideal implementation
Checklist
The text was updated successfully, but these errors were encountered: