Proposed new syntax

Chris Angelico rosuav at gmail.com
Tue Aug 22 11:19:01 EDT 2017


On Wed, Aug 23, 2017 at 1:12 AM, Stephan Houben
<stephanh42 at gmail.com.invalid> wrote:
> Op 2017-08-22, Ian Kelly schreef <ian.g.kelly at gmail.com>:
>> Careful! Python's dunder methods are reserved for use by Python.
>> They're exposed so that we can override them. Calling them directly is
>> generally considered bad style. And in this case specifically, it's
>> not equivalent.
>
> Mmm, you are correct. That's kind of a deception, really.
>
> I have often done things like:
>
>   generate_id = itertools.count().__next__
>
> but I suppose that isn't OK either, then.

That one probably won't bite you, but that doesn't mean it's correct.

General rule of thumb: Dunders are for defining, not for calling.

ChrisA



More information about the Python-list mailing list