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
"""Example of protocol to support multiple types.""" | |
from dataclasses import dataclass | |
from typing_extensions import Protocol | |
class SaucePan: | |
def heat_water(self) -> None: | |
pass |
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
"""Example of Union to support multiple types.""" | |
from dataclasses import dataclass | |
from typing import Union | |
@dataclass | |
class TeaMaker: | |
""" | |
A robot that makes tea. | |
""" |
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
"""Example of Any, bit of an antipattern.""" | |
from dataclasses import dataclass | |
from typing import Any | |
@dataclass | |
class TeaMaker: | |
""" | |
A robot that makes tea. | |
""" |
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
"""Some functionally equivalent classes.""" | |
class SaucePan: | |
def heat_water(self): | |
pass | |
class Kettle: | |
def heat_water(self): | |
pass |
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
"""Some dispenser subclasses.""" | |
class Caddy(Dispenser): | |
def dispense(self): | |
"""Gives an object at home.""" | |
pass | |
class SpacePouch(Dispenser): | |
def dispense(self): |
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
"""Simple dataclass example""" | |
from dataclasses import dataclass | |
@dataclass | |
class TeaMaker: | |
""" | |
A robot that makes tea. | |
""" |
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
class Boiler: | |
"""Water heating.""" | |
def heat_water(self): | |
"""Heats water.""" | |
pass | |
class Dispenser: | |
"""Gives out objects.""" |
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
"""Type hint example""" | |
class TeaMaker: | |
""" | |
A robot that makes tea. | |
""" | |
def __init__(self, | |
boiler: Boiler, |
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
"""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 |
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
#!/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 " |
NewerOlder