-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add rudimentary mypy type checking #5575
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ env/ | |
.tox | ||
.cache | ||
.pytest_cache | ||
.mypy_cache | ||
.coverage | ||
.coverage.* | ||
coverage.xml | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,8 @@ def __init__(self, rawcode): | |
def __eq__(self, other): | ||
return self.raw == other.raw | ||
|
||
__hash__ = None | ||
# Ignore type because of https://github.com/python/mypy/issues/4266. | ||
__hash__ = None # type: ignore | ||
|
||
def __ne__(self, other): | ||
return not self == other | ||
|
@@ -188,11 +189,11 @@ def path(self): | |
""" path to the source code """ | ||
return self.frame.code.path | ||
|
||
def getlocals(self): | ||
@property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that one is a breaking change of the api There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
def locals(self): | ||
""" locals of underlaying frame """ | ||
return self.frame.f_locals | ||
|
||
locals = property(getlocals, None, None, "locals of underlaying frame") | ||
|
||
def getfirstlinesource(self): | ||
return self.frame.code.firstlineno | ||
|
||
|
@@ -255,11 +256,11 @@ def __str__(self): | |
line = "???" | ||
return " File %r:%d in %s\n %s\n" % (fn, self.lineno + 1, name, line) | ||
|
||
@property | ||
def name(self): | ||
""" co_name of underlaying code """ | ||
return self.frame.code.raw.co_name | ||
|
||
name = property(name, None, None, "co_name of underlaying code") | ||
bluetech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class Traceback(list): | ||
""" Traceback objects encapsulate and offer higher level | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -547,6 +547,8 @@ def __init__(self, targetfd, tmpfile=None): | |
self.start = lambda: None | ||
self.done = lambda: None | ||
else: | ||
self.start = self._start | ||
self.done = self._done | ||
if targetfd == 0: | ||
assert not tmpfile, "cannot set tmpfile with stdin" | ||
tmpfile = open(os.devnull, "r") | ||
|
@@ -568,7 +570,7 @@ def __repr__(self): | |
self.targetfd, getattr(self, "targetfd_save", None), self._state | ||
) | ||
|
||
def start(self): | ||
def _start(self): | ||
""" Start capturing on targetfd using memorized tmpfile. """ | ||
try: | ||
os.fstat(self.targetfd_save) | ||
|
@@ -585,7 +587,7 @@ def snap(self): | |
self.tmpfile.truncate() | ||
return res | ||
|
||
def done(self): | ||
def _done(self): | ||
""" stop capturing, restore streams, return original capture file, | ||
seeked to position zero. """ | ||
targetfd_save = self.__dict__.pop("targetfd_save") | ||
|
@@ -618,7 +620,8 @@ class FDCapture(FDCaptureBinary): | |
snap() produces text | ||
""" | ||
|
||
EMPTY_BUFFER = str() | ||
# Ignore type because it doesn't match the type in the superclass (bytes). | ||
EMPTY_BUFFER = str() # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the type error here? this should also probably just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There superclass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def snap(self): | ||
res = super().snap() | ||
|
@@ -679,7 +682,8 @@ def writeorg(self, data): | |
|
||
|
||
class SysCaptureBinary(SysCapture): | ||
EMPTY_BUFFER = b"" | ||
# Ignore type because it doesn't match the type in the superclass (str). | ||
EMPTY_BUFFER = b"" # type: ignore | ||
|
||
def snap(self): | ||
res = self.tmpfile.buffer.getvalue() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
from collections import defaultdict | ||
from collections import deque | ||
from collections import OrderedDict | ||
from typing import Dict | ||
from typing import Tuple | ||
|
||
import attr | ||
import py | ||
|
@@ -31,6 +33,9 @@ | |
from _pytest.outcomes import fail | ||
from _pytest.outcomes import TEST_OUTCOME | ||
|
||
if False: # TYPE_CHECKING | ||
from typing import Type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this only imported conditionally, but not the others? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not available in python 3.5.0 / 3.5.1 |
||
|
||
|
||
@attr.s(frozen=True) | ||
class PseudoFixtureDef: | ||
|
@@ -54,10 +59,10 @@ def pytest_sessionstart(session): | |
session._fixturemanager = FixtureManager(session) | ||
|
||
|
||
scopename2class = {} | ||
scopename2class = {} # type: Dict[str, Type[nodes.Node]] | ||
|
||
|
||
scope2props = dict(session=()) | ||
scope2props = dict(session=()) # type: Dict[str, Tuple[str, ...]] | ||
scope2props["package"] = ("fspath",) | ||
scope2props["module"] = ("fspath", "module") | ||
scope2props["class"] = scope2props["module"] + ("cls",) | ||
|
@@ -960,7 +965,8 @@ class FixtureFunctionMarker: | |
scope = attr.ib() | ||
params = attr.ib(converter=attr.converters.optional(tuple)) | ||
autouse = attr.ib(default=False) | ||
ids = attr.ib(default=None, converter=_ensure_immutable_ids) | ||
# Ignore type because of https://github.com/python/mypy/issues/6172. | ||
bluetech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ids = attr.ib(default=None, converter=_ensure_immutable_ids) # type: ignore | ||
bluetech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name = attr.ib(default=None) | ||
|
||
def __call__(self, function): | ||
|
Uh oh!
There was an error while loading. Please reload this page.