Skip to content

Commit

Permalink
pyupgrade --py36-plus **/*.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Jan 2, 2021
1 parent b5468d9 commit a133a6a
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 34 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: pip install --upgrade pip
- run: pip install black codespell flake8 isort pytest pyupgrade tox
- run: black --check . || true
- run: pip install black codespell flake8 isort mypy pytest pyupgrade tox
- run: black --check .
- run: codespell --quiet-level=2 # --ignore-words-list="" --skip=""
- run: flake8 . --count --show-source --statistics
- run: isort --profile black .
- run: tox
- run: pip install -e .
- run: mypy --ignore-missing-imports .
- run: pytest .
- run: pytest --doctest-modules . || true
- run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true
- run: shopt -s globstar && pyupgrade --py36-plus **/*.py
3 changes: 1 addition & 2 deletions patterns/behavioral/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
def count_to(count):
"""Counts by word numbers, up to a maximum of five"""
numbers = ["one", "two", "three", "four", "five"]
for number in numbers[:count]:
yield number
yield from numbers[:count]


# Test the generator
Expand Down
2 changes: 1 addition & 1 deletion patterns/behavioral/memento.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, value):
self.value = value

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

def increment(self):
self.value += 1
Expand Down
2 changes: 1 addition & 1 deletion patterns/behavioral/publish_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def unsubscribe(self, msg):
self.provider.unsubscribe(msg, self)

def run(self, msg):
print("{} got {}".format(self.name, msg))
print(f"{self.name} got {msg}")


def main():
Expand Down
6 changes: 3 additions & 3 deletions patterns/behavioral/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_csv():

def convert_to_text(data):
print("[CONVERT]")
return "{} as text".format(data)
return f"{data} as text"


def saver():
Expand All @@ -33,7 +33,7 @@ def saver():

def template_function(getter, converter=False, to_save=False):
data = getter()
print("Got `{}`".format(data))
print(f"Got `{data}`")

if len(data) <= 3 and converter:
data = converter(data)
Expand All @@ -43,7 +43,7 @@ def template_function(getter, converter=False, to_save=False):
if to_save:
saver()

print("`{}` was processed".format(data))
print(f"`{data}` was processed")


def main():
Expand Down
4 changes: 2 additions & 2 deletions patterns/creational/abstract_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def show_pet(self):
"""Creates and shows a pet using the abstract factory"""

pet = self.pet_factory()
print("We have a lovely {}".format(pet))
print("It says {}".format(pet.speak()))
print(f"We have a lovely {pet}")
print(f"It says {pet.speak()}")


class Dog:
Expand Down
2 changes: 1 addition & 1 deletion patterns/dependency_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def production_code_time_provider() -> str:
datetime for this example).
"""
current_time = datetime.datetime.now()
current_time_formatted = "{}:{}".format(current_time.hour, current_time.minute)
current_time_formatted = f"{current_time.hour}:{current_time.minute}"
return current_time_formatted


Expand Down
4 changes: 2 additions & 2 deletions patterns/structural/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
# ConcreteImplementor 1/2
class DrawingAPI1:
def draw_circle(self, x, y, radius):
print("API1.circle at {}:{} radius {}".format(x, y, radius))
print(f"API1.circle at {x}:{y} radius {radius}")


# ConcreteImplementor 2/2
class DrawingAPI2:
def draw_circle(self, x, y, radius):
print("API2.circle at {}:{} radius {}".format(x, y, radius))
print(f"API2.circle at {x}:{y} radius {radius}")


# Refined Abstraction
Expand Down
4 changes: 2 additions & 2 deletions patterns/structural/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, wrapped):
self._wrapped = wrapped

def render(self):
return "<b>{}</b>".format(self._wrapped.render())
return f"<b>{self._wrapped.render()}</b>"


class ItalicWrapper(TextTag):
Expand All @@ -52,7 +52,7 @@ def __init__(self, wrapped):
self._wrapped = wrapped

def render(self):
return "<i>{}</i>".format(self._wrapped.render())
return f"<i>{self._wrapped.render()}</i>"


def main():
Expand Down
4 changes: 2 additions & 2 deletions patterns/structural/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Memory:
"""

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


class SolidStateDrive:
Expand All @@ -60,7 +60,7 @@ class SolidStateDrive:
"""

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


class ComputerFacade:
Expand Down
2 changes: 1 addition & 1 deletion patterns/structural/flyweight.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __new__(cls, value, suit):
# self.value, self.suit = value, suit

def __repr__(self):
return "<Card: {}{}>".format(self.value, self.suit)
return f"<Card: {self.value}{self.suit}>"


def main():
Expand Down
7 changes: 3 additions & 4 deletions patterns/structural/mvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Price(float):
__str__ functionality."""

def __str__(self):
return "{:.2f}".format(self)
return f"{self:.2f}"

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

def __iter__(self):
for item in self.products:
yield item
yield from self.products

def get(self, product):
try:
Expand Down Expand Up @@ -86,7 +85,7 @@ def show_item_information(self, item_type, item_name, item_info):
print(printout)

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


class Controller:
Expand Down
6 changes: 2 additions & 4 deletions tests/creational/test_lazy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import unittest

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

def test_extended_properties(self):
print(u"John's relatives: {0}".format(self.John.relatives))
print(f"John's relatives: {self.John.relatives}")
self.assertDictEqual(
{
"name": "John",
Expand All @@ -31,7 +29,7 @@ def test_extended_properties(self):
)

def test_relatives_after_access(self):
print(u"John's relatives: {0}".format(self.John.relatives))
print(f"John's relatives: {self.John.relatives}")
self.assertIn("relatives", self.John.__dict__)

def test_parents(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/creational/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def test_frozen_pool(self):
class TestNaitivePool(unittest.TestCase):

"""def test_object(queue):
queue_object = QueueObject(queue, True)
print('Inside func: {}'.format(queue_object.object))"""
queue_object = QueueObject(queue, True)
print('Inside func: {}'.format(queue_object.object))"""

def test_pool_behavior_with_single_object_inside(self):
sample_queue = queue.Queue()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_hsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ def test_calling_next_state_shall_change_current_state(cls):
cls.hsm._current_state = Standby(cls.hsm) # initial state

def test_method_perform_switchover_shall_return_specifically(cls):
""" Exemplary HierachicalStateMachine method test.
(here: _perform_switchover()). Add additional test cases... """
"""Exemplary HierachicalStateMachine method test.
(here: _perform_switchover()). Add additional test cases..."""
return_value = cls.hsm._perform_switchover()
expected_return_value = "perform switchover"
cls.assertEqual(return_value, expected_return_value)


class StandbyStateTest(unittest.TestCase):
""" Exemplary 2nd level state test class (here: Standby state). Add missing
state test classes... """
"""Exemplary 2nd level state test class (here: Standby state). Add missing
state test classes..."""

@classmethod
def setUpClass(cls):
Expand Down

0 comments on commit a133a6a

Please sign in to comment.