We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
Hi, sorry to create an issue for what may be a newbie question, but I've browsed the closed issues and the problem seems to occur often.
I have a dataclass that should hold a list of instances of another class:
@define class SimRecipe: SimulationTasks: List[SimulationTask] = []
I didn't realize that SimulationTasks would be a class variable instead of an instance variable.
SimulationTasks
In #972 (comment) it's suggested to give an initial value so that the variable becomes an instance variable, but that doesn't seem to work here.
What would be the cleanest way to make it an instance variable?
Best wishes
The text was updated successfully, but these errors were encountered:
SimulationTasks is not an instance variable, but I suspect I know what's happening:
You're setting a default of a list ([]) that is shared between all instance variables.
[]
What you need to do is = attrs.Factory(list) or = attrs.field(factory=list)
= attrs.Factory(list)
= attrs.field(factory=list)
This is the Python mistake that everyone makes and comparable to the classic def f(x=[]):
def f(x=[]):
Sorry, something went wrong.
Yes, that was precisely what was happening, all SimRecipe instances shared the same SimulationTasks list.
SimRecipe
Thanks for the quick help!
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
Hi, sorry to create an issue for what may be a newbie question, but I've browsed the closed issues and the problem seems to occur often.
I have a dataclass that should hold a list of instances of another class:
I didn't realize that
SimulationTasks
would be a class variable instead of an instance variable.In #972 (comment) it's suggested to give an initial value so that the variable becomes an instance variable, but that doesn't seem to work here.
What would be the cleanest way to make it an instance variable?
Best wishes
The text was updated successfully, but these errors were encountered: