Skip to content

Commit 0267b25

Browse files
committed
Fix some check_untyped_defs mypy errors in terminal
1 parent 5dca7a2 commit 0267b25

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/_pytest/terminal.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
import sys
1010
import time
1111
from functools import partial
12+
from typing import Callable
13+
from typing import Dict
14+
from typing import List
15+
from typing import Mapping
16+
from typing import Optional
17+
from typing import Set
1218

1319
import attr
1420
import pluggy
@@ -195,8 +201,8 @@ class WarningReport:
195201
file system location of the source of the warning (see ``get_location``).
196202
"""
197203

198-
message = attr.ib()
199-
nodeid = attr.ib(default=None)
204+
message = attr.ib(type=str)
205+
nodeid = attr.ib(type=Optional[str], default=None)
200206
fslocation = attr.ib(default=None)
201207
count_towards_summary = True
202208

@@ -240,7 +246,7 @@ def __init__(self, config, file=None):
240246
self.reportchars = getreportopt(config)
241247
self.hasmarkup = self._tw.hasmarkup
242248
self.isatty = file.isatty()
243-
self._progress_nodeids_reported = set()
249+
self._progress_nodeids_reported = set() # type: Set[str]
244250
self._show_progress_info = self._determine_show_progress_info()
245251
self._collect_report_last_write = None
246252

@@ -619,7 +625,7 @@ def _printcollecteditems(self, items):
619625
# because later versions are going to get rid of them anyway
620626
if self.config.option.verbose < 0:
621627
if self.config.option.verbose < -1:
622-
counts = {}
628+
counts = {} # type: Dict[str, int]
623629
for item in items:
624630
name = item.nodeid.split("::", 1)[0]
625631
counts[name] = counts.get(name, 0) + 1
@@ -750,7 +756,9 @@ def getreports(self, name):
750756

751757
def summary_warnings(self):
752758
if self.hasopt("w"):
753-
all_warnings = self.stats.get("warnings")
759+
all_warnings = self.stats.get(
760+
"warnings"
761+
) # type: Optional[List[WarningReport]]
754762
if not all_warnings:
755763
return
756764

@@ -763,7 +771,9 @@ def summary_warnings(self):
763771
if not warning_reports:
764772
return
765773

766-
reports_grouped_by_message = collections.OrderedDict()
774+
reports_grouped_by_message = (
775+
collections.OrderedDict()
776+
) # type: collections.OrderedDict[str, List[WarningReport]]
767777
for wr in warning_reports:
768778
reports_grouped_by_message.setdefault(wr.message, []).append(wr)
769779

@@ -900,11 +910,11 @@ def summary_stats(self):
900910
else:
901911
self.write_line(msg, **main_markup)
902912

903-
def short_test_summary(self):
913+
def short_test_summary(self) -> None:
904914
if not self.reportchars:
905915
return
906916

907-
def show_simple(stat, lines):
917+
def show_simple(stat, lines: List[str]) -> None:
908918
failed = self.stats.get(stat, [])
909919
if not failed:
910920
return
@@ -914,7 +924,7 @@ def show_simple(stat, lines):
914924
line = _get_line_with_reprcrash_message(config, rep, termwidth)
915925
lines.append(line)
916926

917-
def show_xfailed(lines):
927+
def show_xfailed(lines: List[str]) -> None:
918928
xfailed = self.stats.get("xfailed", [])
919929
for rep in xfailed:
920930
verbose_word = rep._get_verbose_word(self.config)
@@ -924,15 +934,15 @@ def show_xfailed(lines):
924934
if reason:
925935
lines.append(" " + str(reason))
926936

927-
def show_xpassed(lines):
937+
def show_xpassed(lines: List[str]) -> None:
928938
xpassed = self.stats.get("xpassed", [])
929939
for rep in xpassed:
930940
verbose_word = rep._get_verbose_word(self.config)
931941
pos = _get_pos(self.config, rep)
932942
reason = rep.wasxfail
933943
lines.append("{} {} {}".format(verbose_word, pos, reason))
934944

935-
def show_skipped(lines):
945+
def show_skipped(lines: List[str]) -> None:
936946
skipped = self.stats.get("skipped", [])
937947
fskips = _folded_skips(skipped) if skipped else []
938948
if not fskips:
@@ -958,9 +968,9 @@ def show_skipped(lines):
958968
"S": show_skipped,
959969
"p": partial(show_simple, "passed"),
960970
"E": partial(show_simple, "error"),
961-
}
971+
} # type: Mapping[str, Callable[[List[str]], None]]
962972

963-
lines = []
973+
lines = [] # type: List[str]
964974
for char in self.reportchars:
965975
action = REPORTCHAR_ACTIONS.get(char)
966976
if action: # skipping e.g. "P" (passed with output) here.
@@ -1084,8 +1094,8 @@ def build_summary_stats_line(stats):
10841094
return parts, main_color
10851095

10861096

1087-
def _plugin_nameversions(plugininfo):
1088-
values = []
1097+
def _plugin_nameversions(plugininfo) -> List[str]:
1098+
values = [] # type: List[str]
10891099
for plugin, dist in plugininfo:
10901100
# gets us name and version!
10911101
name = "{dist.project_name}-{dist.version}".format(dist=dist)
@@ -1099,7 +1109,7 @@ def _plugin_nameversions(plugininfo):
10991109
return values
11001110

11011111

1102-
def format_session_duration(seconds):
1112+
def format_session_duration(seconds: float) -> str:
11031113
"""Format the given seconds in a human readable manner to show in the final summary"""
11041114
if seconds < 60:
11051115
return "{:.2f}s".format(seconds)

0 commit comments

Comments
 (0)