Skip to content

Instantly share code, notes, and snippets.

@jajeffries
Created February 18, 2021 19:03
Show Gist options
  • Save jajeffries/4489fddbb0c476de2a2c1996bee738e2 to your computer and use it in GitHub Desktop.
Save jajeffries/4489fddbb0c476de2a2c1996bee738e2 to your computer and use it in GitHub Desktop.
Python North West 18/2/21
# examples.py
def example1(a: int):
return a + 1
print(example1(2))
print(example1("hello"))
def example2(a: int):
return a * 3
print(example2(2))
print(example2("hello"))
from typing import List
def example3(a: List[int]):
for b in a:
print(b + 1)
example3([1,2,3])
example3(123)
example3(["1",2,"3"])
# main.py
from typing import Any, Protocol, Union
class Message:
def __init__(self, text):
self.text = text
class HasText(Protocol):
text: bool
def write_to_audit_log(m: HasText):
if m.text:
print(m.text)
# ...
print(audit_log_message)
write_to_audit_log(Message("Message 1"))
class AnotherThingToAuditLog:
text = "Hi PyNW"
write_to_audit_log(AnotherThingToAuditLog())
class IncomingMessage:
def __init__(self, text):
self.text = text
write_to_audit_log(IncomingMessage("Message 2"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment