[Tutor] Why begin a function name with an underscore

eryksun eryksun at gmail.com
Tue Aug 28 15:24:38 CEST 2012


On Tue, Aug 28, 2012 at 9:08 AM, Peter Otten <__peter__ at web.de> wrote:
>
> That would reject "floats with an integral value" and therefore doesn't
> comply with the -- non-existing -- spec.

Gotcha.

>>     >>> import numbers
>>     >>> isinstance("42", numbers.Integral)
>>     False
>>     >>> numbers.Integral.register(str)
>>     >>> isinstance("42", numbers.Integral)
>>     True
>
> That's quite an elaborate scheme to shoot yourself in the foot ;)

It was just a quick example. In practice what could happen is someone
would register an integer-like class (instead of subclassing
numbers.Integral or numbers.Number) that is incomplete and ends up
raising an exception.


More information about the Tutor mailing list