-
Notifications
You must be signed in to change notification settings - Fork 4
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
Need to fix Line arguments to List instead of Tuple #45
Comments
Hi Adrian, class Test(object):
def __init__(self, a=[]):
self.a = a
t1 = Test()
t2 = Test()
print(t1.a, t2.a)
# gives: "[] []"
# I append something to the first object
t1.a.append(3)
print(t1.a, t2.a)
# gives: "[3] [3]!!!!" In fact the .a members of the two objects point to the same list!!! |
Ah I see.. Since the tuples also lead to unwanted behaviour, I propose a different approach to resolve both problems at once.. Instantiating the list at the time of class Test(object):
def __init__(self, a=None):
if a is None:
self.a = []
else:
self.a = a
t1 = Test()
t2 = Test()
print(t1.a, t2.a)
# gives: "[] []"
# I append something to the first object
t1.a.append(3)
print(t1.a, t2.a)
# gives: "[3] []" |
This would force us to write explicit constructors for the pysixtrack elements, which we wanted to avoid. The tuple was a way of telling the user that he can rebind Probably the problem can be solved more elegantly modifying the baseclasses... |
... otherwise
Line.append_element
does not work.... throws a
... while initialising the kwargs
elements
andelement_names
with emptyList
instances instead of the default emptyTuple
instances resolves the problem:The text was updated successfully, but these errors were encountered: