-
-
Notifications
You must be signed in to change notification settings - Fork 386
Attribute without type hint in slotted class can't be changed #1173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
attrs never infers the type from a value. If you set an attribute to a value (that's not an attrs.field/attr.ib), it's ignored by attrs and it becomes a class variable that can't be changed with slotted classes. |
Oh, I see. So is my workflow even recommended, or should I always explicitly call @define
class Scenario:
momentum: float = field(default=0.0)
trackDirectory: Path = Path() I do like the shorter version for readability, but I don't want to rely on UNintended features. edit: meant to say UNintended |
No, you can write Attrs picks up everything that is either annotated (except ClassVar) or is assigned a field. |
Okay, good to know I can keep the short version. Thanks for the help! |
Uh oh!
There was an error while loading. Please reload this page.
Hi, so I've just stumbled over something I assume is a misunderstanding on my part, but I want to ask to be sure.
I have a slotted class without type hints:
From the default value of
0.0
I assumed attrs would infer the type ofmomentum
, but when I try to change the value, I get an error:So the type is a
float
as expected, but I can not change the value ofmomentum
.But when I add a type hint:
All works as expected:
So, is this expected/desired behavior and I'm just misunderstanding something? Thanks in advance!
The text was updated successfully, but these errors were encountered: