Dealing with non-callable classmethod objects

Cameron Simpson cs at cskk.id.au
Sat Nov 12 19:12:46 EST 2022


On 13Nov2022 10:08, Cameron Simpson <cs at cskk.id.au> wrote:
>On 13Nov2022 07:57, Cameron Simpson <cs at cskk.id.au> wrote:
>>           # replace fctory with a function calling factory.__func__
>>           factory = lambda arg: factory.__func__(classmethod, arg)
>
>It just occurred to me that you might need to grab the value of 
>factory.__func__ first:
>
>    factory0 = factory
>    factory = lambda arg: factory0.__func__(classmethod, arg)
>
>Otherwise the closure might introduce a recursion.

Or avoid the closure:

     from functools import partial
     ......
     factory = partial(factory.__func__, classmethod)

to produces a partially filled in function.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list