Błażej Michalik <assassink...@gmail.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue28657>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to