Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Un-readable code
import datetime
ymdstr ="%y-%m-%d")
def get_user_info(): pass
def get_client_data(): pass
def get_customer_record(): pass
import time
# What is the number 86400 for again?
import re
address = "One Infinite Loop, Cupertino 95014"
city_zip_code_regex = r"^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$"
matches = re.match(city_zip_code_regex, address)
if matches:
print(f"{matches[1]}: {matches[2]}")
seq = ("Austin", "New York", "San Francisco")
for item in seq:
# Wait, what's `item` again?
class Car:
car_make: str
car_model: str
car_color: str
from typing import List
class Client:
active: bool
def email(client: Client) -> None:
def email_clients(clients: List[Client]) -> None:
"""Filter active clients and send them an email.
for client in clients:
class Email:
def handle(self) -> None:
message = Email()
# What is this supposed to do again?
# type: ignore
def parse_better_js_alternative(code: str) -> None:
regexes = [
# ...
statements = code.split('\n')
tokens = []
for regex in regexes:
for statement in statements:
ast = []
for token in tokens:
for node in ast:
from typing import Text
from tempfile import gettempdir
from pathlib import Path
def create_file(name: Text, temp: bool) -> None:
if temp:
(Path(gettempdir()) / name).touch()
# type: ignore
# This is a module-level name.
# It"s good practice to define these as immutable values, such as a string.
# However...
fullname = "Ryan McDermott"
def split_into_first_and_last_name() -> None:
# The use of the global keyword here is changing the meaning of the
# the following line. This function is now mutating the module-level
# state and introducing a side-effect!
global fullname
fullname = fullname.split()
# MyPy will spot the problem, complaining about 'Incompatible types in
# assignment: (expression has type "List[str]", variable has type "str")'
print(fullname) # ["Ryan", "McDermott"]
# OK. It worked the first time, but what will happen if we call the
# function again?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment