Skip to content

Commit be6f006

Browse files
committed
TR updates, first round
1 parent 38850ca commit be6f006

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

python-raise-exception/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def call_external_api(url):
1010
response = requests.get(url)
1111
response.raise_for_status()
1212
data = response.json()
13-
except requests.exceptions.RequestException as error:
13+
except requests.RequestException as error:
1414
raise APIError(f"{error}") from None
1515
return data
1616

python-raise-exception/devide.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def divide(x, y):
22
for arg in (x, y):
3-
if not isinstance(arg, (int, float)):
3+
if not isinstance(arg, int | float):
44
raise TypeError(f"number expected, got {type(arg).__name__}")
55
if y == 0:
66
raise ValueError("denominator can't be zero")

python-raise-exception/devide2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class MathLibraryError(Exception):
2+
pass
3+
4+
5+
def divide(a, b):
6+
try:
7+
return a / b
8+
except ZeroDivisionError as ex:
9+
raise MathLibraryError(ex)

python-raise-exception/group.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@
1313
print("Handling TypeError")
1414
except* KeyError:
1515
print("Handling KeyError")
16+
17+
18+
try:
19+
raise ExceptionGroup(
20+
"several errors",
21+
[
22+
ValueError("invalid value"),
23+
TypeError("invalid type"),
24+
KeyError("missing key"),
25+
],
26+
)
27+
except ExceptionGroup:
28+
print("Got an exception group!")

python-raise-exception/square.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def squared(numbers):
22
if not isinstance(numbers, list | tuple):
33
raise TypeError(
4-
f'list or tuple expected, got "{type(numbers).__name__}"'
4+
f"list or tuple expected, got '{type(numbers).__name__}'"
55
)
66
return [number**2 for number in numbers]

0 commit comments

Comments
 (0)