Skip to content

Commit 2ee57e2

Browse files
authored
Merge pull request #1 from faif/master
sync 2101
2 parents f6adf63 + c4ef0b7 commit 2ee57e2

18 files changed

Lines changed: 59 additions & 44 deletions

.github/workflows/lint_python.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: lint_python
2+
on: [pull_request, push]
3+
jobs:
4+
lint_python:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- uses: actions/setup-python@v2
9+
- run: pip install --upgrade pip
10+
- run: pip install black codespell flake8 isort mypy pytest pyupgrade tox
11+
- run: black --check .
12+
- run: codespell --quiet-level=2 # --ignore-words-list="" --skip=""
13+
- run: flake8 . --count --show-source --statistics
14+
- run: isort --profile black .
15+
- run: tox
16+
- run: pip install -e .
17+
- run: mypy --ignore-missing-imports . || true
18+
- run: pytest .
19+
- run: pytest --doctest-modules . || true
20+
- run: shopt -s globstar && pyupgrade --py36-plus **/*.py

.travis.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
dist: xenial
1+
os: linux
2+
dist: focal
23
language: python
34

4-
sudo: false
5-
6-
matrix:
5+
jobs:
76
include:
87
- python: "3.7"
98
env: TOXENV=py37
10-
- python: "3.8"
11-
env: TOXENV=py38
9+
- python: "3.9"
10+
env: TOXENV=py39
1211

1312
cache:
1413
- pip
1514

1615
install:
17-
- pip install tox
18-
- pip install codecov
16+
- pip install codecov tox
1917

2018
script:
2119
- tox

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: 2 additions & 2 deletions
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():
@@ -65,7 +65,7 @@ def main():
6565
>>> vani.subscribe("movie")
6666
>>> vani.unsubscribe("movie")
6767
68-
# Note that no one subscirbed to `ads`
68+
# Note that no one subscribed to `ads`
6969
# and that vani changed their mind
7070
7171
>>> fftv.publish("cartoon")

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():

0 commit comments

Comments
 (0)