Skip to content

typing: minor improvements #6509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ def __str__(self) -> str:
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()


Expand All @@ -932,7 +932,7 @@ def __init__(self) -> None:
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)
Expand All @@ -952,7 +952,7 @@ def __init__(
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:
Expand All @@ -969,7 +969,7 @@ def __init__(
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)

Expand All @@ -987,7 +987,7 @@ def __init__(
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":
Expand Down Expand Up @@ -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))


Expand All @@ -1038,7 +1038,7 @@ def __init__(
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)
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def __init__(self, path, lineno: int, message: str) -> None:
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
Expand All @@ -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)

Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from typing import Tuple
from typing import Union

import py

import pytest
from _pytest import outcomes
from _pytest._code.code import ExceptionInfo
Expand Down Expand Up @@ -137,7 +139,7 @@ def __init__(
):
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)
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def __init__(self, filename, firstlineno, tblines, errorstring, argname):
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())
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from _pytest.config import directory_arg
from _pytest.config import hookimpl
from _pytest.config import UsageError
from _pytest.fixtures import FixtureManager
from _pytest.outcomes import exit
from _pytest.runner import collect_one_node
from _pytest.runner import SetupState
Expand Down Expand Up @@ -377,7 +378,10 @@ def __missing__(self, path: str) -> str:
class Session(nodes.FSCollector):
Interrupted = Interrupted
Failed = Failed
# Set on the session by runner.pytest_sessionstart.
_setupstate = None # type: SetupState
# Set on the session by fixtures.pytest_sessionstart.
_fixturemanager = None # type: FixtureManager
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since _fixturemanager is nowhere to be seen in this file, a comment Set on the session by pytest_sessionstart(). would be very helpful here.


def __init__(self, config):
nodes.FSCollector.__init__(
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Node:

def __init__(
self,
name,
name: str,
parent: Optional["Node"] = None,
config: Optional[Config] = None,
session: Optional["Session"] = None,
Expand Down
2 changes: 1 addition & 1 deletion testing/code/test_excinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ def test_reprexcinfo_unicode(self):
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())
Expand Down