Skip to content

Instantly share code, notes, and snippets.

View zeth's full-sized avatar

Zeth zeth

View GitHub Profile
@zeth
zeth / teamaker9.py
Last active May 19, 2019 14:47
Example of Protocol
"""Example of protocol to support multiple types."""
from dataclasses import dataclass
from typing_extensions import Protocol
class SaucePan:
def heat_water(self) -> None:
pass
@zeth
zeth / teamaker8.py
Created May 19, 2019 13:09
An example of Union
"""Example of Union to support multiple types."""
from dataclasses import dataclass
from typing import Union
@dataclass
class TeaMaker:
"""
A robot that makes tea.
"""
@zeth
zeth / teamaker6.py
Created May 19, 2019 13:00
Example of Any
"""Example of Any, bit of an antipattern."""
from dataclasses import dataclass
from typing import Any
@dataclass
class TeaMaker:
"""
A robot that makes tea.
"""
@zeth
zeth / teamaker5.py
Created May 19, 2019 12:47
Some static subtypes
"""Some functionally equivalent classes."""
class SaucePan:
def heat_water(self):
pass
class Kettle:
def heat_water(self):
pass
@zeth
zeth / teamaker4.py
Last active May 19, 2019 14:31
Simple stub subclasses
"""Some dispenser subclasses."""
class Caddy(Dispenser):
def dispense(self):
"""Gives an object at home."""
pass
class SpacePouch(Dispenser):
def dispense(self):
@zeth
zeth / teamaker3.py
Last active May 19, 2019 12:15
Dataclass example
"""Simple dataclass example"""
from dataclasses import dataclass
@dataclass
class TeaMaker:
"""
A robot that makes tea.
"""
@zeth
zeth / teamaker0.py
Last active May 19, 2019 12:49
Some stub classes
class Boiler:
"""Water heating."""
def heat_water(self):
"""Heats water."""
pass
class Dispenser:
"""Gives out objects."""
@zeth
zeth / teamaker2.py
Last active May 19, 2019 12:05
Example of using Python Type Hints
"""Type hint example"""
class TeaMaker:
"""
A robot that makes tea.
"""
def __init__(self,
boiler: Boiler,
@zeth
zeth / teamaker1.py
Last active May 19, 2019 12:03
Simple example of a class, pre-type hints era
"""Simple class example."""
class TeaMaker:
"""
A robot that makes tea.
Args:
boiler (Boiler): Something that can heat water
dispencer (Dispencer): Something that can give teabags
@zeth
zeth / logo.py
Created July 3, 2017 22:30
Quick Python Logo, in Python
#!/usr/bin/python3
"""Quick Hand written Python version of (generated) bash I saw at
https://twitter.com/dmpayton/status/881986444947935232
By Zeth, Public Domain.
"""
IMAGE = ("e1 e1 x19 b6 x15 e1 x18 b1 x1 b6 "
"x14 e1 x18 b8 x14 e1 x23 b3 x14 e1 x15 b11 x1 y2 x11 e1 x14 b12 x1 "
"y3 x10 e1 x14 b12 x1 y3 x10 e1 x14 b3 x10 y3 x10 e1 x14 b3 x1 y12 "