Closed pddg closed 5 years ago
Workaround for v0.2.1 or earlier.
Do not use append
.
class FirstCommand(BaseCommand):
name = 'first'
def get_options(self):
options = super(FirstCommand, self).get_options()
return [Opt()] + options
Sample code is as follows.
Expected
Actual
Why this happened?
Python's list object is mutable.
uroboros.Option
'sget_options()
function return the pointer ofoptions
attribute itself. So the operation on it in the inheritance class also affect its source class.How to fix
Change the implementation of
uroboros.Command.get_options
like permission mechanism of django-restframework's view class.uroboros.Command.options
accepts both ofuroboros.Option
class and its instance for backward compatibility. Check the type of the attribute ofuroboros.Command.options
and instantiate the class if need, and generate new list and return.