I have not been able to assign a value to every member of a struct in this way:
# Doesn't work:
# self.collator_registry[self.collator_address] = {
# deregistered = 0,
# pool_index = self.pool_index_temp,
#}
I think it doesn't work since it's not the correct syntax. The right syntax is:
self.collator_registry[self.collator_address] = {
deregistered: 0,
pool_index: self.pool_index_temp,
}
You should use : instead of the =
But isn't : used for variable declarations, not assignments? Struct syntax.
Not in struct assignments like so (apparently), thinking about that it might be worth changing for better convention but for now you should use : for that.
Yes, it would be better to use =. If it's going to be changed I'll just leave it commented out for now, and do individual assignments in the mean time.
self.collator_registry[self.collator_address].deregistered = 0
self.collator_registry[self.collator_address].pool_index \
= self.pool_index_temp
It seems like a colon (:) doesn't work either.
I still get the same error:
invalid syntax (, line 214).
Where line 214 is deregistered in:
self.collator_registry[self.collator_address] = {
deregistered = 0,
pool_index = self.pool_index_temp,
}
I am pretty sure this works. I was just playing with below example and all is well. Why are you using dict struct with assign operator inside?
testmap: {
a: int128,
b: int128
}[int128]
@public
def __init__(a: int128, b: int128):
self.testmap[1] = {
a: a,
b: b
}
@public
def test123() -> (int128, int128):
self.testmap[1] = {
a: 123,
b: 456
}
return self.testmap[1].a, self.testmap[1].b
@public
def get() -> (int128, int128):
return self.testmap[1].a, self.testmap[1].b
OK, so I had to use the colon (declaration operator) instead of the equals sign (the assignment operator) inside the struct. That seems odd. I want to assign the value 0 to deregistered, and the value self.pool_index_temp to pool_index. I already declared these members in the struct in the preamble.
Ah I realize that inside the struct you are using the key: value syntax.
Yup. Python doesn't accept assigns in dicts like that. It would accept the following however: MyStruct(key1=call, key2=val2, ...). Worth considering as the struct assignment syntax.
The above would require typedef syntax for structs however
I believe this isn't in scope for Vyper discussions - Python does it this way, we do it this way. The syntax is semantically correct btw, you're not doing assignments, you're doing a declaration.
You're declaring a new struct, and assigning it to a variable.
Closing, as I believe the original issue was resolved.
Most helpful comment
I believe this isn't in scope for Vyper discussions - Python does it this way, we do it this way. The syntax is semantically correct btw, you're not doing assignments, you're doing a declaration.
You're declaring a new struct, and assigning it to a variable.