Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply blacken-docs / the black code formatter #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 56 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Record:


class User:
info : str
info: str

@property
def data(self) -> Dict[str, str]:
Expand Down Expand Up @@ -186,8 +186,8 @@ Explicit is better than implicit.
seq = ("Austin", "New York", "San Francisco")

for item in seq:
#do_stuff()
#do_some_other_stuff()
# do_stuff()
# do_some_other_stuff()

# Wait, what's `item` again?
print(item)
Expand All @@ -199,8 +199,8 @@ for item in seq:
locations = ("Austin", "New York", "San Francisco")

for location in locations:
#do_stuff()
#do_some_other_stuff()
# do_stuff()
# do_some_other_stuff()
# ...
print(location)
```
Expand Down Expand Up @@ -290,12 +290,13 @@ class Menu:
self.body = config["body"]
# ...


menu = Menu(
{
"title": "My Menu",
"body": "Something about my menu",
"button_text": "OK",
"cancellable": False
"cancellable": False,
}
)
```
Expand All @@ -312,6 +313,7 @@ class MenuConfig:
button_text: The text for the button label.
cancellable: Can it be cancelled?
"""

title: str
body: str
button_text: str
Expand Down Expand Up @@ -349,6 +351,7 @@ class MenuConfig(NamedTuple):
button_text: The text for the button label.
cancellable: Can it be cancelled?
"""

title: str
body: str
button_text: str
Expand All @@ -364,7 +367,7 @@ create_menu(
MenuConfig(
title="My delicious menu",
body="A description of the various items on the menu",
button_text="Order now!"
button_text="Order now!",
)
)
```
Expand All @@ -390,6 +393,7 @@ class MenuConfig:
button_text: str
cancellable: bool = False


def create_menu(config: MenuConfig):
title, body, button_text, cancellable = astuple(config)
# ...
Expand All @@ -399,7 +403,7 @@ create_menu(
MenuConfig(
title="My delicious menu",
body="A description of the various items on the menu",
button_text="Order now!"
button_text="Order now!",
)
)
```
Expand Down Expand Up @@ -436,7 +440,7 @@ create_menu(
title="My delicious menu",
body="A description of the various items on the menu",
button_text="Order now!",
cancellable=True
cancellable=True,
)
)
```
Expand Down Expand Up @@ -464,8 +468,7 @@ def email(client: Client) -> None:


def email_clients(clients: List[Client]) -> None:
"""Filter active clients and send them an email.
"""
"""Filter active clients and send them an email."""
for client in clients:
if client.active:
email(client)
Expand All @@ -486,14 +489,12 @@ def email(client: Client) -> None:


def get_active_clients(clients: List[Client]) -> List[Client]:
"""Filter active clients.
"""
"""Filter active clients."""
return [client for client in clients if client.active]


def email_clients(clients: List[Client]) -> None:
"""Send an email to a given list of clients.
"""
"""Send an email to a given list of clients."""
for client in get_active_clients(clients):
email(client)
```
Expand All @@ -520,8 +521,7 @@ def active_clients(clients: Iterator[Client]) -> Generator[Client, None, None]:


def email_client(clients: Iterator[Client]) -> None:
"""Send an email to a given list of clients.
"""
"""Send an email to a given list of clients."""
for client in active_clients(clients):
email(client)
```
Expand All @@ -538,6 +538,7 @@ class Email:
def handle(self) -> None:
pass


message = Email()
# What is this supposed to do again?
message.handle()
Expand All @@ -550,6 +551,7 @@ class Email:
def send(self) -> None:
"""Send this message"""


message = Email()
message.send()
```
Expand All @@ -566,12 +568,13 @@ much. Splitting up functions leads to reusability and easier testing.
```python
# type: ignore


def parse_better_js_alternative(code: str) -> None:
regexes = [
# ...
]

statements = code.split('\n')
statements = code.split("\n")
tokens = []
for regex in regexes:
for statement in statements:
Expand All @@ -592,7 +595,7 @@ from typing import Tuple, List, Dict


REGEXES: Tuple = (
# ...
# ...
)


Expand Down Expand Up @@ -689,13 +692,15 @@ If you can do this, you will be happier than the vast majority of other programm
# 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
Expand All @@ -715,6 +720,7 @@ from typing import List, AnyStr
def split_into_first_and_last_name(name: AnyStr) -> List[AnyStr]:
return name.split()


fullname = "Ryan McDermott"
name, surname = split_into_first_and_last_name(fullname)

Expand Down Expand Up @@ -792,64 +798,66 @@ updating multiple places any time you want to change one thing.
from typing import List, Dict
from dataclasses import dataclass


@dataclass
class Developer:
def __init__(self, experience: float, github_link: str) -> None:
self._experience = experience
self._github_link = github_link

@property
def experience(self) -> float:
return self._experience

@property
def github_link(self) -> str:
return self._github_link



@dataclass
class Manager:
def __init__(self, experience: float, github_link: str) -> None:
self._experience = experience
self._github_link = github_link

@property
def experience(self) -> float:
return self._experience

@property
def github_link(self) -> str:
return self._github_link


def get_developer_list(developers: List[Developer]) -> List[Dict]:
developers_list = []
for developer in developers:
developers_list.append({
'experience' : developer.experience,
'github_link' : developer.github_link
})
developers_list.append(
{"experience": developer.experience, "github_link": developer.github_link}
)
return developers_list


def get_manager_list(managers: List[Manager]) -> List[Dict]:
managers_list = []
for manager in managers:
managers_list.append({
'experience' : manager.experience,
'github_link' : manager.github_link
})
managers_list.append(
{"experience": manager.experience, "github_link": manager.github_link}
)
return managers_list


## create list objects of developers
company_developers = [
Developer(experience=2.5, github_link='https://github.com/1'),
Developer(experience=1.5, github_link='https://github.com/2')
Developer(experience=2.5, github_link="https://github.com/1"),
Developer(experience=1.5, github_link="https://github.com/2"),
]
company_developers_list = get_developer_list(developers=company_developers)

## create list objects of managers
company_managers = [
Manager(experience=4.5, github_link='https://github.com/3'),
Manager(experience=5.7, github_link='https://github.com/4')
Manager(experience=4.5, github_link="https://github.com/3"),
Manager(experience=5.7, github_link="https://github.com/4"),
]
company_managers_list = get_manager_list(managers=company_managers)
```
Expand All @@ -860,42 +868,42 @@ company_managers_list = get_manager_list(managers=company_managers)
from typing import List, Dict
from dataclasses import dataclass


@dataclass
class Employee:
def __init__(self, experience: float, github_link: str) -> None:
self._experience = experience
self._github_link = github_link

@property
def experience(self) -> float:
return self._experience

@property
def github_link(self) -> str:
return self._github_link



def get_employee_list(employees: List[Employee]) -> List[Dict]:
employees_list = []
for employee in employees:
employees_list.append({
'experience' : employee.experience,
'github_link' : employee.github_link
})
employees_list.append(
{"experience": employee.experience, "github_link": employee.github_link}
)
return employees_list


## create list objects of developers
company_developers = [
Employee(experience=2.5, github_link='https://github.com/1'),
Employee(experience=1.5, github_link='https://github.com/2')
Employee(experience=2.5, github_link="https://github.com/1"),
Employee(experience=1.5, github_link="https://github.com/2"),
]
company_developers_list = get_employee_list(employees=company_developers)

## create list objects of managers
company_managers = [
Employee(experience=4.5, github_link='https://github.com/3'),
Employee(experience=5.7, github_link='https://github.com/4')
Employee(experience=4.5, github_link="https://github.com/3"),
Employee(experience=5.7, github_link="https://github.com/4"),
]
company_managers_list = get_employee_list(employees=company_managers)
```
Expand Down