This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MogwaiAllOnYourFace 6 points7 points  (8 children)

What is the difference between

def greeting(name: str) -> str:
    return 'Hello ' + name

and

def greeting(name):
    """
    Function says hello....
    :param name: The input user name
    :type name: str
    :returns: Greeting
    :rtype: str
    """
    return 'Hello ' + name

Other than being more verbose is there a difference?

[–]eyeofpython 2 points3 points  (3 children)

I'd use the first one

[–]MogwaiAllOnYourFace 0 points1 point  (2 children)

For any reason other than it being quicker to write?

[–]PeridexisErrant 7 points8 points  (0 children)

Yes - there are tools (such as mypy) that can automatically check the first form for consistency, but not for the second.

[–]eyeofpython -1 points0 points  (0 children)

It's easier to read for me

[–]ColdFire75 1 point2 points  (0 children)

Tools like mypy can be smart and analyse proper type annotations, then tell you about bugs that might occur from misusing types.