Design: Idiom for classes and methods that are customizable by the user?

Dirk Bächle tshortik at gmx.de
Tue May 17 10:51:54 EDT 2016


Hi Michael,

and thanks a lot for chiming in on this topic.

On 13.05.2016 22:33, Michael Selik wrote:
>
>> [...]
>>
> I share Greg's trepidation when I hear a phrase like that, but the general
> idea of a registry of classes or functions and then picking the right one
> based on string input is fine.
>

See my answer to Gregory, addressing his concerns. ;)

> How would the API work for custom Taskmasters? It's not so great to require
> that the user must explicitly ``add`` their derived class after defining
> it. Perhaps that add function could be a decorator?
>

Our current API doesn't use decorators at all, since it's also aimed at people with no (or only some) knowledge of Python. Until a 
year or so ago, we have been backwards compatible down to Python 1.5.2...and then to Python 2.4 for some time. Only during the last 
two months we made a clear cut and are now seeing Python 2.7 as our floor to further develop from.
So to some degree, decorators were technically not possible to support...and would have looked strange to the average user perhaps?

We're now free to add them into the mix for our new Python 2.7.x/3.y codebase, but this would probably require an API discussion 
first. However, I'll keep the "decorator" idea in mind when I get back to putting "all the dots on the i" for the interface.

Best regards,

Dirk




More information about the Python-list mailing list