typing: py.io.TerminalWriter for tw arguments

This commit is contained in:
Daniel Hahler 2020-01-19 10:14:06 +01:00
parent 4e0dbe92dd
commit 5c445b05e7
4 changed files with 15 additions and 13 deletions

View File

@ -921,7 +921,7 @@ class TerminalRepr:
def __repr__(self) -> str:
return "<{} instance at {:0x}>".format(self.__class__, id(self))
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
raise NotImplementedError()
@ -932,7 +932,7 @@ class ExceptionRepr(TerminalRepr):
def addsection(self, name: str, content: str, sep: str = "-") -> None:
self.sections.append((name, content, sep))
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
for name, content, sep in self.sections:
tw.sep(sep, name)
tw.line(content)
@ -952,7 +952,7 @@ class ExceptionChainRepr(ExceptionRepr):
self.reprtraceback = chain[-1][0]
self.reprcrash = chain[-1][1]
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
for element in self.chain:
element[0].toterminal(tw)
if element[2] is not None:
@ -969,7 +969,7 @@ class ReprExceptionInfo(ExceptionRepr):
self.reprtraceback = reprtraceback
self.reprcrash = reprcrash
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
self.reprtraceback.toterminal(tw)
super().toterminal(tw)
@ -987,7 +987,7 @@ class ReprTraceback(TerminalRepr):
self.extraline = extraline
self.style = style
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
# the entries might have different styles
for i, entry in enumerate(self.reprentries):
if entry.style == "long":
@ -1019,7 +1019,7 @@ class ReprEntryNative(TerminalRepr):
def __init__(self, tblines: Sequence[str]) -> None:
self.lines = tblines
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
tw.write("".join(self.lines))
@ -1038,7 +1038,7 @@ class ReprEntry(TerminalRepr):
self.reprfileloc = filelocrepr
self.style = style
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
if self.style == "short":
assert self.reprfileloc is not None
self.reprfileloc.toterminal(tw)
@ -1071,7 +1071,7 @@ class ReprFileLocation(TerminalRepr):
self.lineno = lineno
self.message = message
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
# filename and lineno output for each entry,
# using an output format that most editors understand
msg = self.message
@ -1086,7 +1086,7 @@ class ReprLocals(TerminalRepr):
def __init__(self, lines: Sequence[str]) -> None:
self.lines = lines
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
for line in self.lines:
tw.line(line)
@ -1095,7 +1095,7 @@ class ReprFuncArgs(TerminalRepr):
def __init__(self, args: Sequence[Tuple[str, object]]) -> None:
self.args = args
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
if self.args:
linesofar = ""
for name, value in self.args:

View File

@ -13,6 +13,8 @@ from typing import Sequence
from typing import Tuple
from typing import Union
import py
import pytest
from _pytest import outcomes
from _pytest._code.code import ExceptionInfo
@ -137,7 +139,7 @@ class ReprFailDoctest(TerminalRepr):
):
self.reprlocation_lines = reprlocation_lines
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
for reprlocation, lines in self.reprlocation_lines:
for line in lines:
tw.line(line)

View File

@ -751,7 +751,7 @@ class FixtureLookupErrorRepr(TerminalRepr):
self.firstlineno = firstlineno
self.argname = argname
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
# tw.line("FixtureLookupError: %s" %(self.argname), red=True)
for tbline in self.tblines:
tw.line(tbline.rstrip())

View File

@ -857,7 +857,7 @@ raise ValueError()
from _pytest._code.code import TerminalRepr
class MyRepr(TerminalRepr):
def toterminal(self, tw) -> None:
def toterminal(self, tw: py.io.TerminalWriter) -> None:
tw.line("я")
x = str(MyRepr())