Skip to content

Commit c4ef0b7

Browse files
authored
Merge pull request faif#365 from cclauss/blacken
pyupgrade --py36-plus **/*.py
2 parents b5468d9 + c6d82e1 commit c4ef0b7

File tree

15 files changed

+31
-34
lines changed

15 files changed

+31
-34
lines changed

.github/workflows/lint_python.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ jobs:
77
- uses: actions/checkout@v2
88
- uses: actions/setup-python@v2
99
- run: pip install --upgrade pip
10-
- run: pip install black codespell flake8 isort pytest pyupgrade tox
11-
- run: black --check . || true
10+
- run: pip install black codespell flake8 isort mypy pytest pyupgrade tox
11+
- run: black --check .
1212
- run: codespell --quiet-level=2 # --ignore-words-list="" --skip=""
1313
- run: flake8 . --count --show-source --statistics
1414
- run: isort --profile black .
1515
- run: tox
1616
- run: pip install -e .
17+
- run: mypy --ignore-missing-imports . || true
1718
- run: pytest .
1819
- run: pytest --doctest-modules . || true
19-
- run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true
20+
- run: shopt -s globstar && pyupgrade --py36-plus **/*.py

patterns/behavioral/iterator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
def count_to(count):
1111
"""Counts by word numbers, up to a maximum of five"""
1212
numbers = ["one", "two", "three", "four", "five"]
13-
for number in numbers[:count]:
14-
yield number
13+
yield from numbers[:count]
1514

1615

1716
# Test the generator

patterns/behavioral/memento.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(self, value):
6666
self.value = value
6767

6868
def __repr__(self):
69-
return "<%s: %r>" % (self.__class__.__name__, self.value)
69+
return f"<{self.__class__.__name__}: {self.value!r}>"
7070

7171
def increment(self):
7272
self.value += 1

patterns/behavioral/publish_subscribe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def unsubscribe(self, msg):
4646
self.provider.unsubscribe(msg, self)
4747

4848
def run(self, msg):
49-
print("{} got {}".format(self.name, msg))
49+
print(f"{self.name} got {msg}")
5050

5151

5252
def main():

patterns/behavioral/template.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_csv():
2424

2525
def convert_to_text(data):
2626
print("[CONVERT]")
27-
return "{} as text".format(data)
27+
return f"{data} as text"
2828

2929

3030
def saver():
@@ -33,7 +33,7 @@ def saver():
3333

3434
def template_function(getter, converter=False, to_save=False):
3535
data = getter()
36-
print("Got `{}`".format(data))
36+
print(f"Got `{data}`")
3737

3838
if len(data) <= 3 and converter:
3939
data = converter(data)
@@ -43,7 +43,7 @@ def template_function(getter, converter=False, to_save=False):
4343
if to_save:
4444
saver()
4545

46-
print("`{}` was processed".format(data))
46+
print(f"`{data}` was processed")
4747

4848

4949
def main():

patterns/creational/abstract_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def show_pet(self):
4646
"""Creates and shows a pet using the abstract factory"""
4747

4848
pet = self.pet_factory()
49-
print("We have a lovely {}".format(pet))
50-
print("It says {}".format(pet.speak()))
49+
print(f"We have a lovely {pet}")
50+
print(f"It says {pet.speak()}")
5151

5252

5353
class Dog:

patterns/dependency_injection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def production_code_time_provider() -> str:
7474
datetime for this example).
7575
"""
7676
current_time = datetime.datetime.now()
77-
current_time_formatted = "{}:{}".format(current_time.hour, current_time.minute)
77+
current_time_formatted = f"{current_time.hour}:{current_time.minute}"
7878
return current_time_formatted
7979

8080

patterns/structural/bridge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
# ConcreteImplementor 1/2
1111
class DrawingAPI1:
1212
def draw_circle(self, x, y, radius):
13-
print("API1.circle at {}:{} radius {}".format(x, y, radius))
13+
print(f"API1.circle at {x}:{y} radius {radius}")
1414

1515

1616
# ConcreteImplementor 2/2
1717
class DrawingAPI2:
1818
def draw_circle(self, x, y, radius):
19-
print("API2.circle at {}:{} radius {}".format(x, y, radius))
19+
print(f"API2.circle at {x}:{y} radius {radius}")
2020

2121

2222
# Refined Abstraction

patterns/structural/decorator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, wrapped):
4242
self._wrapped = wrapped
4343

4444
def render(self):
45-
return "<b>{}</b>".format(self._wrapped.render())
45+
return f"<b>{self._wrapped.render()}</b>"
4646

4747

4848
class ItalicWrapper(TextTag):
@@ -52,7 +52,7 @@ def __init__(self, wrapped):
5252
self._wrapped = wrapped
5353

5454
def render(self):
55-
return "<i>{}</i>".format(self._wrapped.render())
55+
return f"<i>{self._wrapped.render()}</i>"
5656

5757

5858
def main():

patterns/structural/facade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Memory:
5151
"""
5252

5353
def load(self, position, data):
54-
print("Loading from {0} data: '{1}'.".format(position, data))
54+
print(f"Loading from {position} data: '{data}'.")
5555

5656

5757
class SolidStateDrive:
@@ -60,7 +60,7 @@ class SolidStateDrive:
6060
"""
6161

6262
def read(self, lba, size):
63-
return "Some data from sector {0} with size {1}".format(lba, size)
63+
return f"Some data from sector {lba} with size {size}"
6464

6565

6666
class ComputerFacade:

0 commit comments

Comments
 (0)