Skip to content

Registering a preloop hook without return type hint throws an error #958

@DarkmatterVale

Description

@DarkmatterVale

As is discussed here, I should be able to declare and register a preloop hook as follows:

class App(cmd2.Cmd):
    def __init__(self, *args, *kwargs):
        super().__init__(*args, **kwargs)
        self.register_preloop_hook(self.myhookmethod)

    def myhookmethod(self):
        self.poutput("before the loop begins")

However, running the above will throw an error: TypeError: initialize_preloop must declare return a return type of 'None'. In order to fix the error, you need to provide a return type hint:

class App(cmd2.Cmd):
    def __init__(self, *args, *kwargs):
        super().__init__(*args, **kwargs)
        self.register_preloop_hook(self.myhookmethod)

    def myhookmethod(self) -> None:
        self.poutput("before the loop begins")

Versions:

  • cmd2: 1.2.0
  • python: 3.7

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions