Skip to content

Commit 5c445b0

Browse files
committed
typing: py.io.TerminalWriter for tw arguments
1 parent 4e0dbe9 commit 5c445b0

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/_pytest/_code/code.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def __str__(self) -> str:
921921
def __repr__(self) -> str:
922922
return "<{} instance at {:0x}>".format(self.__class__, id(self))
923923

924-
def toterminal(self, tw) -> None:
924+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
925925
raise NotImplementedError()
926926

927927

@@ -932,7 +932,7 @@ def __init__(self) -> None:
932932
def addsection(self, name: str, content: str, sep: str = "-") -> None:
933933
self.sections.append((name, content, sep))
934934

935-
def toterminal(self, tw) -> None:
935+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
936936
for name, content, sep in self.sections:
937937
tw.sep(sep, name)
938938
tw.line(content)
@@ -952,7 +952,7 @@ def __init__(
952952
self.reprtraceback = chain[-1][0]
953953
self.reprcrash = chain[-1][1]
954954

955-
def toterminal(self, tw) -> None:
955+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
956956
for element in self.chain:
957957
element[0].toterminal(tw)
958958
if element[2] is not None:
@@ -969,7 +969,7 @@ def __init__(
969969
self.reprtraceback = reprtraceback
970970
self.reprcrash = reprcrash
971971

972-
def toterminal(self, tw) -> None:
972+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
973973
self.reprtraceback.toterminal(tw)
974974
super().toterminal(tw)
975975

@@ -987,7 +987,7 @@ def __init__(
987987
self.extraline = extraline
988988
self.style = style
989989

990-
def toterminal(self, tw) -> None:
990+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
991991
# the entries might have different styles
992992
for i, entry in enumerate(self.reprentries):
993993
if entry.style == "long":
@@ -1019,7 +1019,7 @@ class ReprEntryNative(TerminalRepr):
10191019
def __init__(self, tblines: Sequence[str]) -> None:
10201020
self.lines = tblines
10211021

1022-
def toterminal(self, tw) -> None:
1022+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
10231023
tw.write("".join(self.lines))
10241024

10251025

@@ -1038,7 +1038,7 @@ def __init__(
10381038
self.reprfileloc = filelocrepr
10391039
self.style = style
10401040

1041-
def toterminal(self, tw) -> None:
1041+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
10421042
if self.style == "short":
10431043
assert self.reprfileloc is not None
10441044
self.reprfileloc.toterminal(tw)
@@ -1071,7 +1071,7 @@ def __init__(self, path, lineno: int, message: str) -> None:
10711071
self.lineno = lineno
10721072
self.message = message
10731073

1074-
def toterminal(self, tw) -> None:
1074+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
10751075
# filename and lineno output for each entry,
10761076
# using an output format that most editors understand
10771077
msg = self.message
@@ -1086,7 +1086,7 @@ class ReprLocals(TerminalRepr):
10861086
def __init__(self, lines: Sequence[str]) -> None:
10871087
self.lines = lines
10881088

1089-
def toterminal(self, tw) -> None:
1089+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
10901090
for line in self.lines:
10911091
tw.line(line)
10921092

@@ -1095,7 +1095,7 @@ class ReprFuncArgs(TerminalRepr):
10951095
def __init__(self, args: Sequence[Tuple[str, object]]) -> None:
10961096
self.args = args
10971097

1098-
def toterminal(self, tw) -> None:
1098+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
10991099
if self.args:
11001100
linesofar = ""
11011101
for name, value in self.args:

src/_pytest/doctest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from typing import Tuple
1414
from typing import Union
1515

16+
import py
17+
1618
import pytest
1719
from _pytest import outcomes
1820
from _pytest._code.code import ExceptionInfo
@@ -137,7 +139,7 @@ def __init__(
137139
):
138140
self.reprlocation_lines = reprlocation_lines
139141

140-
def toterminal(self, tw) -> None:
142+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
141143
for reprlocation, lines in self.reprlocation_lines:
142144
for line in lines:
143145
tw.line(line)

src/_pytest/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ def __init__(self, filename, firstlineno, tblines, errorstring, argname):
751751
self.firstlineno = firstlineno
752752
self.argname = argname
753753

754-
def toterminal(self, tw) -> None:
754+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
755755
# tw.line("FixtureLookupError: %s" %(self.argname), red=True)
756756
for tbline in self.tblines:
757757
tw.line(tbline.rstrip())

testing/code/test_excinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ def test_reprexcinfo_unicode(self):
857857
from _pytest._code.code import TerminalRepr
858858

859859
class MyRepr(TerminalRepr):
860-
def toterminal(self, tw) -> None:
860+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
861861
tw.line("я")
862862

863863
x = str(MyRepr())

0 commit comments

Comments
 (0)