PyWart: Language missing maximum constant of numeric types!

Wolfgang Meiners WolfgangMeiners01 at
Sun Feb 26 08:16:24 EST 2012

Am 25.02.12 21:35, schrieb Rick Johnson:
> On Feb 25, 11:54 am, MRAB <pyt... at> wrote:
>> [...]
>> That should be:
>> if maxlength is not None and len(string) <= maxlength:
> Using "imaginary" infinity values defiles the intuitive nature of your
> code. What is more intuitive?
> def confine_length(string, maxlength=INFINITY):
>     if string.length < maxlength:
>         do_something()
> def confine_length(string, maxlength=None):
>     if maxlength is not None and len(string) <= maxlength:
>         do_something()

I just had a closer look at it. It seems to be more complicated than i
thougth: You will have to write

def confine_length(string, maxlength=None):
    if maxlength: # maxlength exists, comparison possible
        if len(string) <= maxlength:
    else: # maxlength does not exist, so always do something

you migth also write

def confine_length(str, maxlength=None):
    do_it = (len(str) <= maxlength) if maxlength else True
    if do_it:

but it really does not look intuitive. Hmm. My idea was that None is a
perfect Value for infinity since there is no infinitely large number.
But as i see it, you must have two comparisons then. Maybe someone has a
better idea?


More information about the Python-list mailing list