Python Sanity Proposal: Type Hinting Solution

Rick Johnson rantingrickjohnson at
Fri Jan 23 22:59:46 CET 2015

On Friday, January 23, 2015 at 3:02:57 PM UTC-6, Mario Figueiredo wrote:

> In any case, I agree entirely with you that type
> annotation is one ugly syntax to a programming language
> that is touted everywhere as being simple and easy to
> read. I would say that the mistake started 5 years ago,
> and I am surprised how you guys let that horrible PEP
> pass. I wasn't around then, so I'm off the hook.
> Some folks in here argue that complex type annotations
> will be rare, since functions should be designed as
> straightforward units of code with simple requirements and
> respecting certain best practices, like separation of
> concerns, low cyclomatic complexity, adapt well to simple
> unit tests, bla bla bla. But the actual practice of coding
> software is very different. We generally code bad software
> and generally avoid best practices if they get in the way
> of our schedules, our knowledge, and even our ability. And
> there is always the problem of OOP, which is a magnificent
> source of complex function declarations in terms of the
> types they receive and output.
> I think that you are right in that we shouldn't pollute
> our code with static analysis shit. We shouldn't pollute
> our code period. But There's better ways of doing it
> without resorting to external files.
> I'd say Steven D'Aprano example of Cobra hit my sweet
> spot.

Yes and this is what i meant when i said "cutting the baby
in half". Although stub files have many advantages, i'll
admit they are onerous for the authors. So the compromise
would be to keep the hints in the same file for which they
are applied, but to separate them from the func arguments:

    (Example modified for PEP8 compliance ;-)

    @typehint(arg1:str, arg2:int, returns:bool)
    def myfunction(arg1, arg2): 
        return True 
Of course "@typehint" could be an extension of the decorator
syntax, a keyword, a build-in function or whatever, i don't

That's an acceptable compromise for me. It's not completely
satisfactory, but at least i can read parameters without
needing to ignore type noise -- gawd that is so

    Today's repressed look of disapproval brought to you by:
    Angry Java Programmers Everywhere!

More information about the Python-list mailing list