Type hinting in Eclipse with PyDev

前端 未结 5 948
醉话见心
醉话见心 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 23:06

    I'm not aware of any ways to do type-hinting in Python.

    The standard Pythonic practice is this:

    >>> def adds_three(number):
    ...     '''Returns number + 3'''
    ...     return number + 3
    ...     
    

    Note I've done the following:

    • The function name is clear for its behaviour
    • The argument name is clear as to what it should be
    • The docstring details what the function does
    • Python is a dynamically-typed language. Why restrict the user to put in integer? Floating points also support the operator +. Let them use it.

    One good thing about dynamic typing is that all methods are inheritly overloaded. Of course, you can always do type-checking in the function to prevent fatal errors.

提交回复
热议问题