summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Shao <terrorjack@type.dance>2023-03-30 03:29:35 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2023-03-30 15:47:15 +0100
commitbb5e3a2ccf1589ca7aad9a4e875b1e2e2fc5def9 (patch)
treee58748c7114e086ea9c5a08a4c76ad3246488a52
parent98b5cf67f8428b0daefcbf5df121df0b8a126654 (diff)
downloadhaskell-bb5e3a2ccf1589ca7aad9a4e875b1e2e2fc5def9.tar.gz
testsuite: mypy typing error fixes
This patch fixes some mypy typing errors which weren't caught in previous linting jobs.
-rw-r--r--testsuite/driver/my_typing.py18
-rw-r--r--testsuite/driver/runtests.py8
-rw-r--r--testsuite/driver/testglobals.py3
-rw-r--r--testsuite/driver/testutil.py8
-rw-r--r--testsuite/driver/typing_stubs.py23
5 files changed, 10 insertions, 50 deletions
diff --git a/testsuite/driver/my_typing.py b/testsuite/driver/my_typing.py
index 1bc5e6d578..c7cc1640e5 100644
--- a/testsuite/driver/my_typing.py
+++ b/testsuite/driver/my_typing.py
@@ -8,13 +8,8 @@ The testsuite driver can be typechecked using mypy [1].
[1] http://mypy-lang.org/
"""
-try:
- from typing import *
- import typing
-except:
- # The backwards compatibility stubs must live in another module lest
- # mypy complains.
- from typing_stubs import * # type: ignore
+from typing import *
+import typing
####################################################
@@ -23,14 +18,7 @@ except:
# N.B. mypy appears to typecheck as though the "then" clause of if structures
# is taken. We exploit this below.
-# TextIO is missing on some older Pythons.
-if 'TextIO' not in globals():
- try:
- from typing import TextIO
- except ImportError:
- TextIO = None # type: ignore
-else:
- TextIO = None # type: ignore
+from typing import TextIO
####################################################
diff --git a/testsuite/driver/runtests.py b/testsuite/driver/runtests.py
index 5cd8b9697f..0924250441 100644
--- a/testsuite/driver/runtests.py
+++ b/testsuite/driver/runtests.py
@@ -29,7 +29,7 @@ import subprocess
from concurrent.futures import ThreadPoolExecutor
from testutil import getStdout, str_warn, str_info, print_table, shorten_metric_name
-from testglobals import getConfig, ghc_env, getTestRun, TestConfig, \
+from testglobals import getConfig, ghc_env, TestConfig, t, \
TestOptions, brokens, PerfMetric
from my_typing import TestName
from perf_notes import MetricChange, GitRef, inside_git_repo, is_worktree_dirty, format_perf_stat, get_abbrev_hash_length, is_commit_hash
@@ -337,8 +337,6 @@ t_files = list(findTFiles(config.rootdirs))
print('Found', len(t_files), '.T files...')
-t = getTestRun() # type: TestRun
-
# Avoid cmd.exe built-in 'date' command on Windows
t.start_time = datetime.datetime.now()
@@ -523,13 +521,13 @@ else:
groups[m.stat.metric].append(m)
- for metric_name, stats in groups.items():
+ for metric_name, stats in groups.items(): # type: ignore
heading = 'Metrics: %s' % metric_name
print()
print(heading)
print('-' * len(heading))
print()
- tabulate_metrics(stats)
+ tabulate_metrics(stats) # type: ignore
else:
print("\nNone collected.")
print("")
diff --git a/testsuite/driver/testglobals.py b/testsuite/driver/testglobals.py
index 62643f2acc..aee48e80aa 100644
--- a/testsuite/driver/testglobals.py
+++ b/testsuite/driver/testglobals.py
@@ -304,9 +304,6 @@ class TestRun:
global t
t = TestRun()
-def getTestRun() -> TestRun:
- return t
-
# -----------------------------------------------------------------------------
# Information about the current test
diff --git a/testsuite/driver/testutil.py b/testsuite/driver/testutil.py
index f2c63c5a2d..220c1f7554 100644
--- a/testsuite/driver/testutil.py
+++ b/testsuite/driver/testutil.py
@@ -29,9 +29,9 @@ def passed(hc_opts=None) -> PassFail:
hc_opts=hc_opts)
def failBecause(reason: str,
- tag: str=None,
- stderr: str=None,
- stdout: str=None
+ tag: Optional[str]=None,
+ stderr: Optional[str]=None,
+ stdout: Optional[str]=None
) -> PassFail:
return PassFail(passed=False, reason=reason, tag=tag,
stderr=stderr, stdout=stdout, hc_opts=None)
@@ -57,7 +57,7 @@ def getStdout(cmd_and_args: List[str]):
if r != 0:
raise Exception("Command failed: " + str(cmd_and_args))
if stderr:
- raise Exception("stderr from command: %s\nStdOut(%s):\n%s\n%s\nOutput(%s):\n%s\n%s\n" % (cmd_and_args,str(len(stdout)), stdout, stdout.decode('utf-8'), str(len(stderr)), stderr, stderr.decode('utf-8')))
+ raise Exception("stderr from command: %s\nStdOut(%s):\n%r\n%s\nOutput(%s):\n%r\n%s\n" % (cmd_and_args,str(len(stdout)), stdout, stdout.decode('utf-8'), str(len(stderr)), stderr, stderr.decode('utf-8')))
return stdout.decode('utf-8')
def lndir(srcdir: Path, dstdir: Path, force_copy=False):
diff --git a/testsuite/driver/typing_stubs.py b/testsuite/driver/typing_stubs.py
deleted file mode 100644
index 5c3cd813fa..0000000000
--- a/testsuite/driver/typing_stubs.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Stub definitions for things provided by the `typing` package for use by older
-# Python versions which don't ship with `typing`.
-
-import collections
-
-class Dummy:
- def __getitem__(self, *args):
- return None
-
-List = Dummy()
-Tuple = Dummy()
-Set = Dummy()
-TextIO = Dummy()
-Iterator = Dummy()
-Callable = Dummy()
-Optional = Dummy()
-Dict = Dummy()
-Union = Dummy()
-Any = Dummy()
-
-NewType = lambda name, ty: ty
-def NamedTuple(name, fields):
- return collections.namedtuple(name, [field[0] for field in fields])