[Python-ideas] replace boolean methods on builtin types with properties [py4k?]

Michael Foord fuzzyman at voidspace.org.uk
Tue Dec 14 14:19:24 CET 2010


On 13 December 2010 22:35, Gregory P. Smith <greg at krypto.org> wrote:

> The number of times I've seen code written that reads well and passes less
> trained code reviews easily such as:
>
> if check_num and mystring and mystring.isdigit:
>    ...
>
> has increased beyond what I can count on one hand.  The code executes and
> even does the right thing part of the time.
>
> Proposal: any method that returns a boolean on builtins like bytes and
> unicode objects be turned into a property in a future python version.  That
> way the above mistake would happen less often.  mystring.isdigit would be a
> boolean rather than a method reference that is always True.
>
> There are many ways of detecting the above beyond code review such as
> making a pylink or pychecker type thing flag them, having proper unittest
> coverage that tests both conditions, etc.  But those are not always in
> place.
>
> A hack could be done today to have these behave as both functions and
> properties by having the property return a callable bool derived class that
> returns itself.  But that seems a bit too cool yet gross...
>
>
bool derived class... good luck with that. :-)

Michael


> -gps
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>


-- 
http://www.voidspace.org.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20101214/f7745a34/attachment.html>


More information about the Python-ideas mailing list