This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Błażej Michalik, remi.lapeyre, rhettinger, tuxtimo
Date 2018-07-10.04:42:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1531197725.35.0.56676864532.issue28657@psf.upfronthosting.co.za>
In-reply-to
Content
>> Could this have been done with:  
>> setattr(self.__class__, "do_" + command, func)?

> Isn't that worse than doing that on an instance? It will work 
> as long as there's only one.

Why not have multiple classes instead of multiple instances?  Then use class composition to combine the components.

FWIW, I just looked through the Cmd2 project (which depends on and extends the Cmd class): https://cmd2.readthedocs.io/en/latest/index.html .  AFAICT, there is no precedent for the approach taken by your project.  This seems to be at odds with the design of module which is class based rather than instance based.

The existing class based design allows class composition which supports needs for separately maintained components.  It also allows regular methods to be dynamically attached to the class or any of its parents after the class is created.   Being regular methods, they would have access to the "self" instance parameter so that the application can be stateful (note that attaching functions to instances loses this advantage).  In Cmd2, the instance is considered the application and only one can be run at a time (it's not really about having multiple distinct instances that vary dynamically and independently of one another).

I've exhausted my triage efforts on this.  It doesn't seem be bug; rather, it is a feature request to take the module in a different direction that seems to be in conflict with its core concept and normal use (and in conflict with Python norms about where to attach methods).  

If you would like to push forward, consider eliciting opinions and analysis from Catherine Devlin and Todd Leonhardt (the maintainers of Cmd2).  If they think it is a good idea to have multiple instances with dynamically attached functions, then this feature request can go forward.
History
Date User Action Args
2018-07-10 04:42:05rhettingersetrecipients: + rhettinger, tuxtimo, Błażej Michalik, remi.lapeyre
2018-07-10 04:42:05rhettingersetmessageid: <1531197725.35.0.56676864532.issue28657@psf.upfronthosting.co.za>
2018-07-10 04:42:05rhettingerlinkissue28657 messages
2018-07-10 04:42:04rhettingercreate