Skip to content

Commit 4a024a3

Browse files
committed
fix: mypy errors
1 parent 3eadc74 commit 4a024a3

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

grading_lib/cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def summary_command() -> None:
4242
@cli.command(name="rebase-todo-injector")
4343
@click.argument("todo_items_file_path")
4444
@click.argument("path")
45-
def rebase_todo_injector_command(todo_items_file_path, path) -> None:
45+
def rebase_todo_injector_command(todo_items_file_path: str, path: str) -> None:
4646
"""
4747
An 'editor' that inject pre-made todo items for git interactive rebase.
4848

grading_lib/qa.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
"""Set of utilities for quality assurance of the grading script."""
22

3+
import typing as ty
34
from importlib import import_module
5+
from types import TracebackType
46

7+
from typing_extensions import Self
58

6-
def import_as_non_testcase(module_name, name, package=None):
9+
10+
def import_as_non_testcase(
11+
module_name: str, name: str, package: str | None = None
12+
) -> ty.Any:
713
"""Import the name from a module and prevent pytest from running it as testcase."""
814
mod = import_module(module_name, package=package)
915
cls = mod.__dict__[name]
@@ -17,13 +23,19 @@ class SetupThenTearDown:
1723
Intended to be used in the QA script.
1824
"""
1925

20-
def __init__(self, obj):
26+
def __init__(self, obj: ty.Any) -> None:
2127
self.obj = obj
2228

23-
def __enter__(self):
29+
def __enter__(self) -> Self:
2430
if hasattr(self.obj, "setUp"):
2531
self.obj.setUp()
26-
27-
def __exit__(self, exc_type, exc_val, exc_tb):
32+
return self
33+
34+
def __exit__(
35+
self,
36+
exc_type: type[BaseException] | None,
37+
exc_val: BaseException | None,
38+
exc_tb: TracebackType | None,
39+
) -> None:
2840
if hasattr(self.obj, "tearDown"):
2941
self.obj.tearDown()

grading_lib/repository.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
import tempfile
55
import uuid
66
from pathlib import Path
7+
from types import TracebackType
78

89
from git import Head, Repo, Tag
910
from git.repo.fun import is_git_dir
11+
from typing_extensions import Self
1012

1113
from .common import BaseTestCase, CommandResult, run_executable
1214

1315

1416
def ensure_git_author_identity(
15-
name="ou-cs3560-grading-script", email="[email protected]"
16-
):
17+
name: str = "ou-cs3560-grading-script",
18+
email: str = "[email protected]",
19+
) -> None:
1720
"""
1821
Set user.name and user.email is not set unless they are already set.
1922
"""
@@ -41,9 +44,9 @@ class Repository:
4144
:raise ValueError: When the repository does not have a working tree directory.
4245
"""
4346

44-
def __init__(self, path: str | Path, *args, **kwargs):
47+
def __init__(self, path: str | Path, *args, **kwargs) -> None:
4548
self.repo: Repo
46-
self.temp_dir: tempfile.TemporaryDirectory | None = None
49+
self.temp_dir: tempfile.TemporaryDirectory[str] | None = None
4750

4851
if isinstance(path, str):
4952
path = Path(path)
@@ -90,10 +93,15 @@ def __init__(self, path: str | Path, *args, **kwargs):
9093

9194
self.working_tree_dir = Path(self.repo.working_tree_dir)
9295

93-
def __enter__(self):
96+
def __enter__(self) -> Self:
9497
return self
9598

96-
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
99+
def __exit__(
100+
self,
101+
exc_type: type[BaseException] | None,
102+
exc_val: BaseException | None,
103+
exc_tb: TracebackType | None,
104+
) -> None:
97105
self.cleanup()
98106

99107
def cleanup(self) -> None:

0 commit comments

Comments
 (0)