Python is DOOMED! Again!

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Jan 23 05:51:28 CET 2015


Sturla Molden wrote:

> Chris Angelico <rosuav at gmail.com> wrote:
> 
>> Uhh... if your managers and customers are stipulating non-Pythonic
>> coding styles, then it's time to find new managers/customers. If
>> they're not writing the code, code quality shouldn't be their concern.
> 
> I am saying the day someone requires me to write a type hint, I will no
> longer be using Python or recommending it. Python is great, but not that
> great.


You probably already write type checks, only you might do it like this:


def my_func(x, index=0):
    if not isinstance(index, int):
        raise TypeError("index must be an integer")
    do_stuff()


or perhaps like this:


def my_func(x, index=0):
    try:
        if index == int(index):
            do_stuff()
    except TypeError:
        raise
    else:
        raise TypeError("index must be an integer, not a float")


And then you write tests to confirm that my_func fails correctly when given
an index which is not an integer. Most of that is monkey-work, so simple
that even the compiler can do it.


How about writing this instead?

def my_func(x, index:int=0): 
    do_stuff()


Is that really such an unspeakable burden? *Always* a burden? You cannot
imagine any circumstances where you would gain some advantage by having an
automated type-checker identify type-related bugs?

Well okay then. Keep working the way you do right now.



-- 
Steven




More information about the Python-list mailing list