Uncategorized November 25, 2013 @ 01:14

Docstring-based Type Inference

Some python coders enjoy torturing themselves by using glorified notepads of which the most advanced feature appears to be syntax coloring. Conveniences such as debugging, code hinting and syntax error reporting would be redundant. After all, you can get all that by using the console and running your program, right?

I guess I’m just a slight bit too lazy for that. I’d like to have my potential coding flaws reveal themselves as quickly as possible. The first few lines I probably typed in Nano, because Python is so much nicer than shell scripting, but while writing more, I went for good ol’ Eclipse ‘n’ PyDev. Awesome stuff, it even has rudimentary refactoring capabilities; SHIFT+CTRL+R has become an comfortable hand pose for me.

After the sprint to deliver our last project, down time set in and that means trying out new stuff. PyCharm! It does most (if not all) that PyDev delivers and then some! Refactoring nearly looks as if it actually works, it looks nice (very important) and it is able to infer function argument types from a well-formatted docstring!

It’s almost like using a strongly-typed language again. Well, not really, but at least you don’t have to look up every little type in an api doc in order to see what is available and how to use it.

Consider this:

class Action():
    def jump():
        pass

def run():
    walk(A())

def walk(v):
    """"
    @type v: Action
    """

    v.

After that dot is typed in, PyCharm will obediently list jump() in a popup list.

It does in fact not warn you about passing unwanted types into that function, but that would defeat the purpose of using Python, wouldn’t it?

Anyhow, I enjoy working with this language more every day, especially when I’m having my collection of braces and crutches to lean on while digging through unexplored territory (read: libraries).

No Comments to Docstring-based Type Inference

Add comment:


You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

By submitting a comment here you grant baseone:online a perpetual license to reproduce your words and name/web site in attribution. Inappropriate or irrelevant comments will be removed at an admin's discretion.