Skip to content

Commit 32b62f7

Browse files
authored
Merge pull request #6509 from blueyed/typing-minor
typing: minor improvements
2 parents 1a75a3c + 5c445b0 commit 32b62f7

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
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())

src/_pytest/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from _pytest.config import directory_arg
1616
from _pytest.config import hookimpl
1717
from _pytest.config import UsageError
18+
from _pytest.fixtures import FixtureManager
1819
from _pytest.outcomes import exit
1920
from _pytest.runner import collect_one_node
2021
from _pytest.runner import SetupState
@@ -377,7 +378,10 @@ def __missing__(self, path: str) -> str:
377378
class Session(nodes.FSCollector):
378379
Interrupted = Interrupted
379380
Failed = Failed
381+
# Set on the session by runner.pytest_sessionstart.
380382
_setupstate = None # type: SetupState
383+
# Set on the session by fixtures.pytest_sessionstart.
384+
_fixturemanager = None # type: FixtureManager
381385

382386
def __init__(self, config):
383387
nodes.FSCollector.__init__(

src/_pytest/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Node:
8080

8181
def __init__(
8282
self,
83-
name,
83+
name: str,
8484
parent: Optional["Node"] = None,
8585
config: Optional[Config] = None,
8686
session: Optional["Session"] = None,

testing/code/test_excinfo.py

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

857857
class MyRepr(TerminalRepr):
858-
def toterminal(self, tw) -> None:
858+
def toterminal(self, tw: py.io.TerminalWriter) -> None:
859859
tw.line("я")
860860

861861
x = str(MyRepr())

0 commit comments

Comments
 (0)