Skip to content

Instantly share code, notes, and snippets.

View yothinix's full-sized avatar

Yothin M yothinix

View GitHub Profile
from typing import Optional
def f(s: Optional[str]) -> None:
...
from typing import Union
def f(s: Union[int, str]) -> None:
...
from typing import TypeVar
T = TypeVar('T')
def f(s: T) -> T:
...
from typing import NewType
USERID = NewType('USERID', int)
def get_username(id: USERID) -> str:
...
from typing import Type
def do_something(t: Type[SomeClass]) -> SomeClass:
...
def f(l: List[str]) -> None:
s = l.pop() # reveal_type(s) -> str
def g(message: str = None) -> None:
if message is None:
return
reveal_type(message) # -> str
from typing import cast
possible_values = function_return_possible_values()
new_type = cast(new_type, possible_values)
from dataclasses import dataclass
@dataclass
class Color:
hue: int
saturation: float
lightness: float = 0.5 # default value
from verbose_dataclasses import dataclass, field
from datatime import datetime
@dataclass(order=True, unsafe_hash=True)
class Employee:
emp_id: int = field()
name: str = field()
gender: str = field()
salary: int = field(hash=False, repr=False, metadata={'units': 'bitcoin'})
age: int = field(hash=False)
@yothinix
yothinix / init.vim
Created May 22, 2018 02:51
Yothinix's init.vim setup
if &compatible
set nocompatible
endif
set runtimepath+=/Users/man/.nvim/bundles/repos/github.com/Shougo/dein.vim
if dein#load_state('/Users/man/.nvim/bundles')
call dein#begin('/Users/man/.nvim/bundles')
call dein#add('/Users/man/.nvim/bundles/repos/github.com/Shougo/dein.vim')