Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
Description
Bug report
Bug description:
importcmdclassSampleShell(cmd.Cmd):""" A sample shell class """defdefault(self,line):print("Got - ",line)defdo_EOF(self,line):returnTrueif__name__=="__main__":SampleShell().cmdloop()
If you execute this simple command shell instance - you find that even when not entering a valid input - the previous result is repeated.
(Cmd)HelloGot-Hello(Cmd)Got-Hello(Cmd)Got-Hello(Cmd)HowareyouGot-Howareyou(Cmd)Got-Howareyou
This seems to be the current default behavior ofdefault in thecmd.Cmd class.
However I don't see why this should be default. For example if one is constructing command interpreters which are say chat applications - that usually don't do any specific commands like "do_command" but override thedefault method - then this has implications as the empty input translates to chat processing of the previous line - which is not the behavior you want.
So right now one has to codeagainst it by caching the last line and checking new input against it. In this case,
classSampleShell(cmd.Cmd):""" A sample shell class """last=Nonedefdefault(self,line):ifline==self.last:returnprint("Got - ",line)self.last=linedefdo_EOF(self,line):returnTrue
Now the behavior is fine.
(Cmd)HelloGot-Hello(Cmd) (Cmd)HiGot-Hi(Cmd) (Cmd)
This is definitely a bug - OR (highly unlikely) a behavior not documented in the module documentation ofcmd or
the documentation is not clear (explicit)
This exists on all Pythion 3.x versions I checked - 3.10, 3.11, 3.12, 3.13, 3.14..
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Projects
Status