Is there a way to implement the ** operator on a custom object

Cameron Simpson cs at cskk.id.au
Fri Feb 9 16:13:23 EST 2024


On 09Feb2024 18:56, Left Right <olegsivokon at gmail.com> wrote:
>But, more to the point: extending collections.abc.Mapping may or may
>not be possible in OP's case.

We don't yet know if that's what the OP had in mind yet, anyway.

>Also, if you are doing this through inheritance, this seems really
>convoluted: why not just inherit from dict? -- less methods to
>implement, less stuff to import etc.

There's a rule of thumb that we _tend_ not to subclass the builtins; it 
certainly has its pitfalls to do with object creation/initialisation.  
That said, I have some classes which subclass dict, int, str and 
namedtuple.

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


More information about the Python-list mailing list