Merge pull request #6509 from blueyed/typing-minor

typing: minor improvements
This commit is contained in:
Daniel Hahler 2020-01-19 11:33:41 +01:00 committed by GitHub
commit 32b62f770f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 14 deletions

View File

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

View File

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

View File

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

View File

@ -15,6 +15,7 @@ from _pytest import nodes
from _pytest.config import directory_arg from _pytest.config import directory_arg
from _pytest.config import hookimpl from _pytest.config import hookimpl
from _pytest.config import UsageError from _pytest.config import UsageError
from _pytest.fixtures import FixtureManager
from _pytest.outcomes import exit from _pytest.outcomes import exit
from _pytest.runner import collect_one_node from _pytest.runner import collect_one_node
from _pytest.runner import SetupState from _pytest.runner import SetupState
@ -377,7 +378,10 @@ class _bestrelpath_cache(dict):
class Session(nodes.FSCollector): class Session(nodes.FSCollector):
Interrupted = Interrupted Interrupted = Interrupted
Failed = Failed Failed = Failed
# Set on the session by runner.pytest_sessionstart.
_setupstate = None # type: SetupState _setupstate = None # type: SetupState
# Set on the session by fixtures.pytest_sessionstart.
_fixturemanager = None # type: FixtureManager
def __init__(self, config): def __init__(self, config):
nodes.FSCollector.__init__( nodes.FSCollector.__init__(

View File

@ -80,7 +80,7 @@ class Node:
def __init__( def __init__(
self, self,
name, name: str,
parent: Optional["Node"] = None, parent: Optional["Node"] = None,
config: Optional[Config] = None, config: Optional[Config] = None,
session: Optional["Session"] = None, session: Optional["Session"] = None,

View File

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