Created
July 27, 2018 17:33
-
-
Save tirkarthi/8e6e01fde74398cac7a4eb7246169956 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List, Dict | |
import sys | |
def get_profile_a(user_id: int, likes: Dict[str, int]) -> Dict[str, int]: | |
return {'user_id': user_id, 'likes': len(likes)} | |
def get_profile_b(user_id, likes): | |
return {'user_id': user_id, 'likes': len(likes.keys())} | |
if len(sys.argv) > 1: | |
get_profile_a() | |
else: | |
get_profile_b() | |
# Without type hints | |
''' | |
➜ cpython git:(error-message-annotations) ✗ ./python foo_signature.py | |
Traceback (most recent call last): | |
File "foo_signature.py", line 13, in <module> | |
get_profile_b() | |
TypeError: get_profile_b() missing 2 required positional arguments: 'user_id' and 'likes' | |
''' | |
# With type hints | |
''' | |
➜ cpython git:(error-message-annotations) ✗ ./python foo_signature.py types | |
Traceback (most recent call last): | |
File "foo_signature.py", line 11, in <module> | |
get_profile_a() | |
TypeError: get_profile_a() missing 2 required positional arguments: 'user_id' and 'likes' | |
annotation: (user_id: <class 'int'>, likes: typing.Dict[str, int], return: typing.Dict[str, int]) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment