I was recently using the cmd module for a project where my CLI could connect to and interact with another host. I implemented prompt in such a way that it would show the IP address when connected. I.e.,
class MyCmd(cmd.Cmd):
...
@property
def prompt(self) -> str:
if self.remote_host.connected():
return f'> ({self.remote_host.ip}) '
else:
return '> '
This worked perfectly fine... until I ran mypy. mypy complained because, in cmd.Cmd, prompt is a class attribute.
Looking at cmd.py, this seems like an odd design choice as all of the references to cmd are through the instance (i.e., self.prompt).