Skip to content

Commit a133a6a

Browse files
committed
pyupgrade --py36-plus **/*.py
1 parent b5468d9 commit a133a6a

File tree

15 files changed

+31
-34
lines changed

15 files changed

+31
-34
lines changed

.github/workflows/lint_python.yml

+4-3
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 .
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

+1-2
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

+1-1
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

+1-1
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

+3-3
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

+2-2
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

+1-1
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

+2-2
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

+2-2
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

+2-2
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:

patterns/structural/flyweight.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __new__(cls, value, suit):
5353
# self.value, self.suit = value, suit
5454

5555
def __repr__(self):
56-
return "<Card: {}{}>".format(self.value, self.suit)
56+
return f"<Card: {self.value}{self.suit}>"
5757

5858

5959
def main():

patterns/structural/mvc.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Price(float):
2929
__str__ functionality."""
3030

3131
def __str__(self):
32-
return "{:.2f}".format(self)
32+
return f"{self:.2f}"
3333

3434
products = {
3535
"milk": {"price": Price(1.50), "quantity": 10},
@@ -40,8 +40,7 @@ def __str__(self):
4040
item_type = "product"
4141

4242
def __iter__(self):
43-
for item in self.products:
44-
yield item
43+
yield from self.products
4544

4645
def get(self, product):
4746
try:
@@ -86,7 +85,7 @@ def show_item_information(self, item_type, item_name, item_info):
8685
print(printout)
8786

8887
def item_not_found(self, item_type, item_name):
89-
print('That {} "{}" does not exist in the records'.format(item_type, item_name))
88+
print(f'That {item_type} "{item_name}" does not exist in the records')
9089

9190

9291
class Controller:

tests/creational/test_lazy.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
import unittest
42

53
from patterns.creational.lazy_evaluation import Person
@@ -19,7 +17,7 @@ def test_relatives_not_in_properties(self):
1917
self.assertNotIn("relatives", self.John.__dict__)
2018

2119
def test_extended_properties(self):
22-
print(u"John's relatives: {0}".format(self.John.relatives))
20+
print(f"John's relatives: {self.John.relatives}")
2321
self.assertDictEqual(
2422
{
2523
"name": "John",
@@ -31,7 +29,7 @@ def test_extended_properties(self):
3129
)
3230

3331
def test_relatives_after_access(self):
34-
print(u"John's relatives: {0}".format(self.John.relatives))
32+
print(f"John's relatives: {self.John.relatives}")
3533
self.assertIn("relatives", self.John.__dict__)
3634

3735
def test_parents(self):

tests/creational/test_pool.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def test_frozen_pool(self):
3131
class TestNaitivePool(unittest.TestCase):
3232

3333
"""def test_object(queue):
34-
queue_object = QueueObject(queue, True)
35-
print('Inside func: {}'.format(queue_object.object))"""
34+
queue_object = QueueObject(queue, True)
35+
print('Inside func: {}'.format(queue_object.object))"""
3636

3737
def test_pool_behavior_with_single_object_inside(self):
3838
sample_queue = queue.Queue()

tests/test_hsm.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ def test_calling_next_state_shall_change_current_state(cls):
3535
cls.hsm._current_state = Standby(cls.hsm) # initial state
3636

3737
def test_method_perform_switchover_shall_return_specifically(cls):
38-
""" Exemplary HierachicalStateMachine method test.
39-
(here: _perform_switchover()). Add additional test cases... """
38+
"""Exemplary HierachicalStateMachine method test.
39+
(here: _perform_switchover()). Add additional test cases..."""
4040
return_value = cls.hsm._perform_switchover()
4141
expected_return_value = "perform switchover"
4242
cls.assertEqual(return_value, expected_return_value)
4343

4444

4545
class StandbyStateTest(unittest.TestCase):
46-
""" Exemplary 2nd level state test class (here: Standby state). Add missing
47-
state test classes... """
46+
"""Exemplary 2nd level state test class (here: Standby state). Add missing
47+
state test classes..."""
4848

4949
@classmethod
5050
def setUpClass(cls):

0 commit comments

Comments
 (0)