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 Błażej Michalik
Recipients Błażej Michalik, remi.lapeyre, rhettinger, tuxtimo
Date 2018-07-03.17:59:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1530640760.09.0.56676864532.issue28657@psf.upfronthosting.co.za>
In-reply-to
Content
I found it.

Our app had CLI that was so vast, that it didn't made sense to put all of the 'do_xyz' methods into the same class that would run the interface internals. Instead, we had a child Cmd class that had a "add_command(self, command, func, helpstring=None)" method. 

That method would then perform an assignment with setattr() calls: setattr(self, "do_" + command, func). That's why the title of this issue has the innocent setattr() mentioned. I didn't knew at the time, whether or not the usage of it was important to the issue.

It made sense to us back then, since we had multiple components waiting for the user to interact with them, that mostly didn't had much of anything to do with each other. 
It also made keeping track of the commands much easier. Each component had its own set of command, callback and helpstring triplets, and putting them together into the Cmd class was a responsibility of a completely separate code.

It looked cleaner that way.

When I was talking about "modifying class definition", I had a "OurCmd().__class__.do_xyz = callback" situation in mind. I think that it makes it behave in the same way as with the patch, as long as there is only one OurCmd instance.
History
Date User Action Args
2018-07-03 17:59:20Błażej Michaliksetrecipients: + Błażej Michalik, rhettinger, tuxtimo, remi.lapeyre
2018-07-03 17:59:20Błażej Michaliksetmessageid: <1530640760.09.0.56676864532.issue28657@psf.upfronthosting.co.za>
2018-07-03 17:59:20Błażej Michaliklinkissue28657 messages
2018-07-03 17:59:20Błażej Michalikcreate