Skip to content

Commit 38eaa86

Browse files
committed
fixed small issues after review
1 parent 0a7461d commit 38eaa86

12 files changed

Lines changed: 31 additions & 32 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ The Live Website is available at [http://www.academis.eu/advanced_python](http:/
1111

1212
## License
1313

14-
© 2018 Dr. Kristian Rother (krother@academis.eu)
14+
© 2026 Dr. Kristian Rother (krother@academis.eu)
1515

1616
The code is distributed under the conditions of the MIT License.

classes/class_diagram.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Class Diagrams
33

4-
One of the first and most important things converting ideas and into code is to structure data.
4+
One of the first and most important things converting ideas into code is to structure data.
55
You want to start structuring your core business data.
66
In the case of a snake game, this means how the playing field, the snake and the food items are represented.
77

@@ -53,8 +53,8 @@ The Python `dataclasses` module saves you a lot of typing:
5353
@dataclass
5454
class PlayingField:
5555

56-
size: (int, int)
57-
food: (int, int) = None
56+
size: tuple[int, int]
57+
food: tuple[int, int] | None = None
5858

5959
def add_food(self, x, y):
6060
...
@@ -78,7 +78,7 @@ The code is already executable:
7878
print(pf.size)
7979
print(pf.get_walls())
8080

81-
Although our class does nothing yet, it helps to think about your desing and write other code that depends on it.
81+
Although our class does nothing yet, it helps to think about your design and write other code that depends on it.
8282

8383
----
8484

@@ -94,7 +94,7 @@ There are a few differences:
9494
* size and food have separate x and y attributes instead of being tuples
9595
* the walls are represented by a list of `(int, int)` tuples
9696
* the `add_food()` method expects a tuple instead of two integers
97-
* there methods `is_wall()` and `get_walls()` are no longer there
97+
* the methods `is_wall()` and `get_walls()` are no longer there
9898

9999
One could discuss a lot which design is better.
100100
You are better off postponing that discussion to a cleanup stage once the code is running.
@@ -121,7 +121,7 @@ Now you can use all three attributes without storing redundant data:
121121

122122

123123
More complex and difficult questions arise when planning relationships between multiple classes.
124-
There will be multiple working alternatives, but some may fall on your feet in the long run.
124+
There will be multiple working alternatives, each with their own tradeoffs.
125125
You may want to read more about **SOLID principles**, **Object Composition** and **Design Patterns**.
126126

127127
## Classes vs SQL

classes/classes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Defining a class
2424

2525
To define a class, you need to define three things:
2626

27-
- give the class a name (in ``SnakeCase``)
27+
- give the class a name in ``CamelCase``)
2828
- define attributes (variables that belong to the class)
2929
- define methods (functions that belong to the class)
3030

@@ -43,12 +43,12 @@ Creating Objects
4343
----------------
4444

4545
To use a class, you need to create an object from it first. Objects are
46-
*“live versions”* of a class, the class being an idealized abstration
46+
*“live versions”* of a class, the class being an idealized abstraction
4747
(in the sense of `Platos Theory of Forms <https://en.wikipedia.org/wiki/Theory_of_forms>`__).
4848
If you think of **Planet** as a class, the actual planets **Earth** and **Pandalor**
4949
would be the objects of that class.
5050

51-
You can create multiple objects from a class, and each objects has its
51+
You can create multiple objects from a class, and each object has its
5252
own, independent attributes. Syntactically, you can think of a class as a function that returns
5353
objects. (This is a gross oversimplification to what textbooks on
5454
classes say, but in Python it is more or less what happens).

concurrency/gauss_elim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from copy import deepcopy
33
import numpy as np
44

5-
def solve_linear(data: list[float]) -> list[float]:
5+
def solve_linear(data: list[list[float]]) -> list[float]:
66
"""solves linear equations with the Gauss Elimination method"""
77
nrows = len(data)
88
ncols = len(data[0])

error_handling/generate_maze_buggy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def generate_floor_positions(xsize: int, ysize:int) -> set[tuple[int, int]]:
4646
"""
4747
positions = get_all_floor_positions(xsize, ysize)
4848
floors = set()
49-
while positions != []:
49+
while positions:
5050
x, y = random.choice(positions)
5151
neighbors = get_neighbors(x, y)
5252
free = [for nb in neighbors if nb in floors]

error_handling/loggers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
log.setLevel(logging.INFO)
77

88
fmt='%(asctime)s | %(message)s'
9-
format = logging.Formatter(fmt, datefmt='%m/%d/%Y %I:%M:%S %p')
9+
formatter = logging.Formatter(fmt, datefmt='%m/%d/%Y %I:%M:%S %p')
1010

1111
handler = logging.StreamHandler(sys.stderr)
12-
handler.setFormatter(format)
12+
handler.setFormatter(formatter)
1313
log.addHandler(handler)
1414

1515
handler2 = logging.FileHandler('logfile.log', mode='w')
16-
handler2.setFormatter(format)
16+
handler2.setFormatter(formatter)
1717
log.addHandler(handler2)
1818

1919
log.info('message from logger ')

exercises/exercise_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ def func(*args):
1717
return 3 + len(args)
1818

1919

20-
print func(4, 4, 4)
20+
print(func(4, 4, 4))
2121

functions/decorators.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Using built-in decorators
1111
-------------------------
1212

1313
Most of the time, you will use built-in decorators. One example is
14-
``functools.lru_cache`` that memorizes the output of a function to save
14+
``functools.lru_cache`` that memoizes the output of a function to save
1515
time later. Let's decorate a function with it:
1616

1717
.. code:: python3
@@ -42,7 +42,7 @@ Writing your own decorators
4242
---------------------------
4343

4444
If want to add functionality for which no decorator exists,
45-
e.g. printing a timestamp for every addition, you could define a new function:
45+
e.g. printing a timestamp for every call of ``fibonacci()``, you could define a new function:
4646

4747
.. code:: python3
4848
@@ -59,11 +59,11 @@ using a decorator:
5959
6060
def print_timestamp(func):
6161
def wrapper(*args):
62-
print(time.asctime()) # done before addition
63-
result = func(*args) # calls the addition function
64-
... # actions after addition
62+
print(time.asctime()) # done before function call
63+
result = func(*args) # calls the function
64+
... # actions after function call
6565
return result
66-
return wrapper
66+
return wrapper
6767
6868
6969
@print_timestamp
@@ -74,7 +74,7 @@ using a decorator:
7474
return fibonacci(n-1) + fibonacci(n-2)
7575
7676
You can argue that this does not simplify the code.
77-
Decorators pays off in bigger programs, when they are used often.
77+
Decorators pay off in bigger programs, when they are used several times.
7878
Logging function calls is a good example for using a decorator.
7979

8080

@@ -94,11 +94,11 @@ original one. It is useful when writing your own decorators.
9494
def print_timestamp(func):
9595
@functools.wraps(func)
9696
def wrapper(*args):
97-
print(time.asctime()) # done before addition
98-
result = func(*args) # calls the addition function
99-
... # actions after addition
97+
print(time.asctime())
98+
result = func(*args)
99+
...
100100
return result
101-
return wrapper
101+
return wrapper
102102
103103
@print_timestamp
104104
def fibonacci(n):
@@ -109,4 +109,4 @@ original one. It is useful when writing your own decorators.
109109
110110
111111
# check docstring - would not work without @wraps
112-
print(help(addition))
112+
print(help(fibonacci))

quality/type_annotations.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@
2222
def calc_total_price(basket: Basket, prices: FruitPrices) -> float:
2323
...
2424

25-
2625
basket = {"apple", "cantaloupe"}
2726
print(calc_total_price(...))

refactoring/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ When you are working on your first real-world Python project, the codebase is ty
2121

2222
**Refactoring is improving the structure of code without changing its functionality.**
2323

24-
In practice, this means thing like:
24+
In practice, this means things like:
2525

2626
* remove redundant code segments
2727
* split long functions into shorter ones

0 commit comments

Comments
 (0)