Reputation: 29
is this ok to use super() in init like this?
class Command:
def __init__(self, command_payload: bytearray, command_type, command_identifier: int,
command_arguments: List[str]):
self._command_payload = command_payload
self._command_type = command_type
self._command_identifier = command_identifier
self._command_arguments = command_arguments
class ShellExecuteCommand(Command):
def __init__(self, command_type, command_identifier: int, command_arguments: List[str], shell_command):
super.__init__(self, command_type, command_identifier,)
command_arguments = [shell_command]
self._command_arguments = command_arguments
Upvotes: 2
Views: 50
Reputation: 371
It looks like you are using super
the way it's intended but you need to actually call the built-in function by placing parentheses after it, like so:
class ShellExecuteCommand(Command):
def __init__(self, command_type, command_identifier: int, command_arguments: List[str], shell_command):
# notice ``super().__init__``, not ``super.__init__``
super().__init__(self, command_type, command_identifier,)
command_arguments = [shell_command]
self._command_arguments = command_arguments
but yes it's ok to use super
to call the superclasses' __init__
method as you are doing here -- that's the most common use!
https://realpython.com/python-super/#what-can-super-do-for-you
Upvotes: 1