Skip to content

Commit

Permalink
Fix bunch of mypy violations
Browse files Browse the repository at this point in the history
  • Loading branch information
malfet committed Jun 4, 2024
1 parent 2179e95 commit e648608
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/get_tutorials_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_file_names(
return rc


def table_exists(table_name: str) -> bool:
def table_exists(table_name: str) -> Optional[bool]:
"""
Determines whether a table exists. As a side effect, stores the table in
a member variable.
Expand Down
5 changes: 3 additions & 2 deletions .github/scripts/run_with_env_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys


def run_cmd_or_die(cmd):
def run_cmd_or_die(cmd: str) -> str:
print(f"Running command: {cmd}")
p = subprocess.Popen(
"/bin/bash",
Expand All @@ -16,6 +16,7 @@ def run_cmd_or_die(cmd):
bufsize=1,
universal_newlines=True,
)
assert p.stdin is not None and p.stdout is not None
p.stdin.write("set -e\n")
p.stdin.write(cmd)
p.stdin.write("\nexit $?\n")
Expand All @@ -39,7 +40,7 @@ def run_cmd_or_die(cmd):
return result


def main():
def main() -> None:
all_secrets = json.loads(os.environ["ALL_SECRETS"])
secrets_names = [x for x in sys.argv[1].split(" ") if x]
if not secrets_names:
Expand Down
12 changes: 6 additions & 6 deletions .github/scripts/test_compute_and_upload_ci_wait_time_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def normalize_workflow_runs(records: pd.DataFrame) -> pd.DataFrame:


class TestComputeAndUploadCiWaitTimeMetric(TestCase):
def assertDataFramesAreEqual(self, df1: pd.DataFrame, df2: pd.DataFrame):
def assertDataFramesAreEqual(self, df1: pd.DataFrame, df2: pd.DataFrame) -> None:
# Validate the results. We use numpy because the indexes on the dataframes is expected to be different
self.assertTrue(np.array_equal(df1.values, df2.values))

def test_removing_cancelled_jobs(self):
def test_removing_cancelled_jobs(self) -> None:
records = pd.json_normalize(
[
{
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_removing_cancelled_jobs(self):
actual = remove_cancelled_jobs(records)
self.assertDataFramesAreEqual(actual, expected)

def test_normalizing_start_times(self):
def test_normalizing_start_times(self) -> None:
records = pd.json_normalize(
[
{
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_normalizing_start_times(self):
]
self.assertDataFramesAreEqual(actual, expected)

def test_remove_irrelevant_success_jobs(self):
def test_remove_irrelevant_success_jobs(self) -> None:
records = normalize_workflow_runs(
pd.json_normalize(
[
Expand Down Expand Up @@ -261,7 +261,7 @@ def test_remove_irrelevant_success_jobs(self):
]
self.assertDataFramesAreEqual(actual, expected)

def test_remove_irrelevant_failure_jobs(self):
def test_remove_irrelevant_failure_jobs(self) -> None:
records = normalize_workflow_runs(
pd.json_normalize(
[
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_remove_irrelevant_failure_jobs(self):
actual = remove_irrelevant_failure_jobs(records)
self.assertDataFramesAreEqual(actual, expected)

def test_get_pr_level_stats(self):
def test_get_pr_level_stats(self) -> None:
records = normalize_workflow_runs(
pd.json_normalize(
[
Expand Down
15 changes: 8 additions & 7 deletions .github/scripts/test_update_disabled_issues.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Any

Check warning

Code scanning / lintrunner

UFMT/format Warning test

Run lintrunner -a to apply this patch.
from unittest import main, mock, TestCase

from update_disabled_issues import (
Expand Down Expand Up @@ -83,7 +84,7 @@

@mock.patch("test_update_disabled_issues.get_disable_issues")
class TestUpdateDisabledIssues(TestCase):
def test_filter_disable_issues(self, mock_get_disable_issues):
def test_filter_disable_issues(self, mock_get_disable_issues: Any) -> None:
mock_get_disable_issues.return_value = sorted(
MOCK_DATA, key=lambda x: x["number"]
)
Expand All @@ -98,7 +99,7 @@ def test_filter_disable_issues(self, mock_get_disable_issues):
[item["number"] for item in disabled_jobs], [32132, 42345, 94861]
)

def test_condense_disable_tests(self, mock_get_disable_issues):
def test_condense_disable_tests(self, mock_get_disable_issues: Any) -> None:
mock_get_disable_issues.return_value = MOCK_DATA

disabled_issues = get_disable_issues("dummy token")
Expand All @@ -125,7 +126,7 @@ def test_condense_disable_tests(self, mock_get_disable_issues):
results,
)

def test_condense_disable_jobs(self, mock_get_disable_issues):
def test_condense_disable_jobs(self, mock_get_disable_issues: Any) -> None:
mock_get_disable_issues.return_value = MOCK_DATA

disabled_issues = get_disable_issues("dummy token")
Expand Down Expand Up @@ -173,7 +174,7 @@ def test_condense_disable_jobs(self, mock_get_disable_issues):
results,
)

def test_unstable_jobs(self, mock_get_disable_issues):
def test_unstable_jobs(self, mock_get_disable_issues: Any) -> None:
mock_get_disable_issues.return_value = MOCK_UNSTABLE_DATA

unstable_issues = get_disable_issues("dummy token", prefix=UNSTABLE_PREFIX)
Expand Down Expand Up @@ -216,7 +217,7 @@ def test_unstable_jobs(self, mock_get_disable_issues):
results,
)

def test_unauthorized_condense_disable_jobs(self, mock_get_disable_issues):
def test_unauthorized_condense_disable_jobs(self, mock_get_disable_issues: Any) -> None:
mock_get_disable_issues.return_value = MOCK_DATA

disabled_issues = get_disable_issues("dummy token")
Expand All @@ -237,10 +238,10 @@ def test_unauthorized_condense_disable_jobs(self, mock_get_disable_issues):
# Nothing should be disabled here because of the lack of permission
self.assertFalse(results)

def test_unauthorized_unstable_jobs(self, mock_get_disable_issues):
def test_unauthorized_unstable_jobs(self, mock_get_disable_issues: Any) -> None:
mock_get_disable_issues.return_value = MOCK_UNSTABLE_DATA

unstable_issues = get_disable_issues("dummy token", MOCK_UNSTABLE_DATA)
unstable_issues = get_disable_issues("dummy token", MOCK_UNSTABLE_DATA) # type: ignore[arg-type]

_, unstable_jobs = filter_disable_issues(
unstable_issues, prefix=UNSTABLE_PREFIX
Expand Down
6 changes: 3 additions & 3 deletions .github/scripts/update_disabled_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def can_disable_jobs(owner: str, repo: str, username: str, token: str) -> bool:

def condense_disable_tests(
disable_issues: List[Dict[str, Any]],
) -> Dict[str, Tuple]:
) -> Dict[str, Tuple[str, str, List[str]]]:
disabled_test_from_issues = {}
for item in disable_issues:
issue_url = item["url"]
Expand Down Expand Up @@ -184,7 +184,7 @@ def condense_disable_jobs(
repo: str,
token: str,
prefix: str = DISABLED_PREFIX,
) -> Dict[str, Tuple]:
) -> Dict[str, Tuple[str, str, str, str, str, str]]:
disabled_job_from_issues = {}
for item in disable_issues:
issue_url = item["url"]
Expand Down Expand Up @@ -225,7 +225,7 @@ def condense_disable_jobs(
return disabled_job_from_issues


def dump_json(data: Dict[str, Any], filename: str):
def dump_json(data: Dict[str, Any], filename: str) -> None:
with open(filename, mode="w") as file:
json.dump(data, file, sort_keys=True, indent=2)

Expand Down

0 comments on commit e648608

Please sign in to comment.