Last active
July 10, 2020 08:44
-
-
Save keisuke-umezawa/0bced8f655d6e963084669dea9c14cec to your computer and use it in GitHub Desktop.
Un-readable code
This file contains 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
import datetime | |
ymdstr = datetime.date.today().strftime("%y-%m-%d") |
This file contains 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
def get_user_info(): pass | |
def get_client_data(): pass | |
def get_customer_record(): pass |
This file contains 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
import time | |
# What is the number 86400 for again? | |
time.sleep(86400) |
This file contains 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
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]}") |
This file contains 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
seq = ("Austin", "New York", "San Francisco") | |
for item in seq: | |
#do_stuff() | |
#do_some_other_stuff() | |
# Wait, what's `item` again? | |
print(item) |
This file contains 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 Car: | |
car_make: str | |
car_model: str | |
car_color: str |
This file contains 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
from typing import List | |
class Client: | |
active: bool | |
def email(client: Client) -> None: | |
pass | |
def email_clients(clients: List[Client]) -> None: | |
"""Filter active clients and send them an email. | |
""" | |
for client in clients: | |
if client.active: | |
email(client) |
This file contains 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 Email: | |
def handle(self) -> None: | |
pass | |
message = Email() | |
# What is this supposed to do again? | |
message.handle() |
This file contains 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: ignore | |
def parse_better_js_alternative(code: str) -> None: | |
regexes = [ | |
# ... | |
] | |
statements = code.split('\n') | |
tokens = [] | |
for regex in regexes: | |
for statement in statements: | |
pass | |
ast = [] | |
for token in tokens: | |
pass | |
for node in ast: | |
pass |
This file contains 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
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() | |
else: | |
Path(name).touch() |
This file contains 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: 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() | |
split_into_first_and_last_name() | |
# 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