Type hinting in Eclipse with PyDev

前端 未结 5 934
醉话见心
醉话见心 2021-02-18 22:02

I\'m studying Python, after a lot of PHP experience, and it would be handy to have type-hinting in Python. Looks like Eclipse with PyDev doesn\'t support this. Any sug

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-18 22:57

    As of August 2014 there is a proposal by Guido Van Rossum to use mypy syntax annotate type in function definitions, stating that the new syntax is actually valid Python 3. An example from his proposal (not yet a PEP as of September 2014)

    from typing import List, Dict
    
    def word_count(input: List[str]) -> Dict[str, int]:
        result = {}  #type: Dict[str, int]
        for line in input:
            for word in line.split():
                result[word] = result.get(word, 0) + 1
        return result
    

提交回复
热议问题