Tools for static type checking in Python

前端 未结 7 2011
灰色年华
灰色年华 2020-12-01 09:00

I\'m working with a large existing Python codebase and would like to start adding in type annotations so I can get some level of static checking. I\'m imagining something l

7条回答
  •  渐次进展
    2020-12-01 09:25

    There is the 'gradual' package for Python 3; see PIP or the Bitbucket Repo

    Apparently this is an implementation by the group around Jeremy Siek who seems to be quite an authority in the field of gradual typing.

    Some annotations are apparently necessary, here is an example:

    from gradual import *
    
    @typed
    def calculate_total(a:int, b:int) -> int:
        return a + b//100
    

    As far as annotations go, this is not so bad. I have not used the package so I cannot speak to its quality, but the syntax (and the people behind it) certainly make it look promising.

提交回复
热议问题