Created
October 2, 2021 10:06
-
-
Save MartinThoma/b903dd4aefc634d2839dafb65de23645 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 TypedDict, TypeGuard | |
class User(TypedDict): | |
name: str | |
email: str | |
def is_user(data: dict) -> TypeGuard[User]: | |
return "name" in data and "email" in data | |
if __name__ == "__main__": | |
user = {"name": "Martin", "email": "[email protected]"} | |
user = {} | |
if is_user(user): | |
print(user["x"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment