Created
August 9, 2020 11:42
-
-
Save jaycosaur/6e1d690beafa2d91f6696d5c1648c17f to your computer and use it in GitHub Desktop.
Implicit vs Explicit typing [python] - Typescript to Python field guide
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 Sequence | |
from dataclasses import dataclass | |
@dataclass | |
class Person: | |
name: str | |
age: int | |
height: float | |
friends: Sequence[Person] | |
# in Python, unless using Protocols, variables must implement types explicitly | |
jane = Person( | |
name="Jane", | |
age=25, | |
height=1.74, | |
friends=[] | |
) | |
tim = Person( | |
name="Tim", | |
age=23, | |
height=1.71, | |
friends=[jane] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment