Skip to content

Instantly share code, notes, and snippets.

@jaycosaur
Created August 9, 2020 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaycosaur/6e1d690beafa2d91f6696d5c1648c17f to your computer and use it in GitHub Desktop.
Save jaycosaur/6e1d690beafa2d91f6696d5c1648c17f to your computer and use it in GitHub Desktop.
Implicit vs Explicit typing [python] - Typescript to Python field guide
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