Skip to content

Commit 62b450f

Browse files
committed
Merge branch 'main' into chore/setup-local-dev-env
2 parents 8b457e1 + a04aa30 commit 62b450f

5 files changed

Lines changed: 18 additions & 20 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
- id: check-added-large-files
1212
args: [--maxkb=6000]
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.11.4
14+
rev: v0.12.2
1515
hooks:
1616
# Ruff fix
1717
- id: ruff
@@ -23,7 +23,7 @@ repos:
2323
types_or: [python, pyi]
2424
name: ruff (format)
2525
- repo: https://github.com/google/yamlfmt
26-
rev: v0.16.0
26+
rev: v0.17.2
2727
hooks:
2828
- id: yamlfmt
2929
name: YAML (format)

pyproject.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,15 @@ dev = [
3737
[tool.pytest.ini_options]
3838
addopts = "-v --tb=short"
3939

40-
# Ruff
4140
[tool.ruff]
4241
# Line length (Black default)
4342
line-length = 88
44-
# Python target version
45-
target-version = "py310"
4643

4744
# Ignored rules for the entire project
4845
[tool.ruff.lint]
4946
ignore = [
5047
"E501", # Line too long
5148
"E203", # Whitespace before ':'
52-
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` is deprecated and results in slower code
5349
# "TRY301", # Raise within try block (this is actually a good practice)
5450
# "W503" # Line break before binary operator (not PEP8 enforced, so not implemented in Ruff)
5551
]
@@ -86,6 +82,8 @@ select = [
8682
# but Python by default will raise a TypeError via vars(solution_result)
8783
# if the result is not a class and therefore doesn't have a __dict__ attribute.
8884
"tutorial/tests/test_object_oriented_programming.py" = ["B904"]
85+
# Ignore invalid names like `import torch.nn.functional as F`
86+
"25_library_pytorch_language_modeling.ipynb" = ["N812"]
8987

9088
# Ruff formatting
9189
[tool.ruff.format]

tutorial/tests/test_05_object_oriented_programming.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, first_name: str, last_name: str):
3838

3939
def validate_oop_person(solution_result):
4040
assert not isinstance(
41-
solution_result, (str, int, float, bool, list, dict, tuple, set)
41+
solution_result, str | int | float | bool | list | dict | tuple | set
4242
), "Solution must return a class instance, not a datatype."
4343
assert type(solution_result).__module__ != "builtins", (
4444
"Solution must return an instance of a custom class, not a built-in type."
@@ -214,7 +214,7 @@ def __eq__(self, other):
214214

215215
def validate_oop_compare_persons(solution_result):
216216
assert not isinstance(
217-
solution_result, (str, int, float, bool, list, dict, tuple, set)
217+
solution_result, str | int | float | bool | list | dict | tuple | set
218218
), "Solution must return a class instance, not a datatype."
219219
assert type(solution_result).__module__ != "builtins", (
220220
"Solution must return an instance of a custom class, not a built-in type."
@@ -280,7 +280,7 @@ def __str__(self):
280280

281281
def validate_ice_cream_scoop(solution_result):
282282
assert not isinstance(
283-
solution_result, (str, int, float, bool, list, dict, tuple, set)
283+
solution_result, str | int | float | bool | list | dict | tuple | set
284284
), "The returned list must contain class instances, not datatypes."
285285
assert type(solution_result).__module__ != "builtins", (
286286
"The returned list must contain instances of a custom class, not a built-in type."
@@ -369,7 +369,7 @@ def __str__(self):
369369

370370
def validate_ice_cream_bowl(solution_result):
371371
assert not isinstance(
372-
solution_result, (str, int, float, bool, list, dict, tuple, set)
372+
solution_result, str | int | float | bool | list | dict | tuple | set
373373
), "Solution must return a class instance, not a datatype."
374374
assert type(solution_result).__module__ != "builtins", (
375375
"Solution must return an instance of a custom class, not a built-in type."
@@ -396,13 +396,13 @@ def validate_ice_cream_bowl(solution_result):
396396
raise SubAssertionError from None
397397
assert len(attrs) == 1, "The class should have 1 attribute."
398398
assert "scoops" in attrs, "The class attribute should be 'scoops'."
399-
assert isinstance(solution_result.scoops, (list, set, tuple)), (
399+
assert isinstance(solution_result.scoops, list | set | tuple), (
400400
"The class attribute 'scoops' should be a datatype that acts as a container."
401401
)
402402
for scoop in solution_result.scoops:
403-
assert not isinstance(scoop, (str, int, float, bool, list, dict, tuple, set)), (
404-
"The 'scoops' container must contain class instances, not datatypes."
405-
)
403+
assert not isinstance(
404+
scoop, str | int | float | bool | list | dict | tuple | set
405+
), "The 'scoops' container must contain class instances, not datatypes."
406406
assert type(scoop).__module__ != "builtins", (
407407
"The 'scoops' container must contain instances of a custom class, not a built-in type."
408408
)
@@ -467,7 +467,7 @@ def __le__(self, other):
467467

468468
def validate_ice_cream_shop(solution_result):
469469
assert not isinstance(
470-
solution_result, (str, int, float, bool, list, dict, tuple, set)
470+
solution_result, str | int | float | bool | list | dict | tuple | set
471471
), "Solution must return a class instance, not a datatype."
472472
assert type(solution_result).__module__ != "builtins", (
473473
"Solution must return an instance of a custom class, not a built-in type."
@@ -490,7 +490,7 @@ def validate_ice_cream_shop(solution_result):
490490
raise SubAssertionError from None
491491
assert len(attrs) == 1, "The class should have 1 attribute."
492492
assert "flavors" in attrs, "The class attribute should be 'flavors'."
493-
assert isinstance(solution_result.flavors, (list, set, tuple)), (
493+
assert isinstance(solution_result.flavors, list | set | tuple), (
494494
"The class attribute 'flavors' should be a datatype that acts as a container."
495495
)
496496

tutorial/tests/test_13_object_oriented_programming_advanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def set_eye_color(self):
4040

4141
def validate_child_eye_color(solution_result):
4242
assert not isinstance(
43-
solution_result, (str, int, float, bool, list, dict, tuple, set)
43+
solution_result, str | int | float | bool | list | dict | tuple | set
4444
), "Solution must return a class instance, not a datatype."
4545
assert type(solution_result).__module__ != "builtins", (
4646
"Solution must return an instance of a custom class, not a built-in type."

tutorial/tests/testsuite/ast_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def __init__(self, module_file: pathlib.Path) -> None:
1919
tree = ast.parse(self.module_file.read_text(encoding="utf-8"))
2020

2121
for node in tree.body:
22-
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
22+
if isinstance(node, ast.FunctionDef | ast.AsyncFunctionDef):
2323
self.function_defs[node.name] = node
24-
elif isinstance(node, (ast.Import, ast.ImportFrom)) and hasattr(
24+
elif isinstance(node, ast.Import | ast.ImportFrom) and hasattr(
2525
node, "module"
2626
):
2727
for n in node.names:
@@ -83,7 +83,7 @@ def get_solution_code(self, name: str) -> str:
8383
)
8484
for node in function_file_tree.body:
8585
if (
86-
isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
86+
isinstance(node, ast.FunctionDef | ast.AsyncFunctionDef)
8787
and node.name == f
8888
):
8989
solution_code += ast.unparse(node) + "\n\n"

0 commit comments

Comments
 (0)