Remove no longer needed noqa: F821 uses
Not needed since pyflakes 2.2.0.
This commit is contained in:
@@ -98,12 +98,12 @@ class AlwaysDispatchingPrettyPrinter(pprint.PrettyPrinter):
|
||||
level: int,
|
||||
) -> None:
|
||||
# Type ignored because _dispatch is private.
|
||||
p = self._dispatch.get(type(object).__repr__, None) # type: ignore[attr-defined] # noqa: F821
|
||||
p = self._dispatch.get(type(object).__repr__, None) # type: ignore[attr-defined]
|
||||
|
||||
objid = id(object)
|
||||
if objid in context or p is None:
|
||||
# Type ignored because _format is private.
|
||||
super()._format( # type: ignore[misc] # noqa: F821
|
||||
super()._format( # type: ignore[misc]
|
||||
object, stream, indent, allowance, context, level,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -146,7 +146,7 @@ class pytestPDB:
|
||||
|
||||
# Type ignored because mypy doesn't support "dynamic"
|
||||
# inheritance like this.
|
||||
class PytestPdbWrapper(pdb_cls): # type: ignore[valid-type,misc] # noqa: F821
|
||||
class PytestPdbWrapper(pdb_cls): # type: ignore[valid-type,misc]
|
||||
_pytest_capman = capman
|
||||
_continued = False
|
||||
|
||||
@@ -349,7 +349,7 @@ def _enter_pdb(
|
||||
rep.toterminal(tw)
|
||||
tw.sep(">", "entering PDB")
|
||||
tb = _postmortem_traceback(excinfo)
|
||||
rep._pdbshown = True # type: ignore[attr-defined] # noqa: F821
|
||||
rep._pdbshown = True # type: ignore[attr-defined]
|
||||
post_mortem(tb)
|
||||
return rep
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ class DoctestItem(pytest.Item):
|
||||
failures = [] # type: List[doctest.DocTestFailure]
|
||||
# Type ignored because we change the type of `out` from what
|
||||
# doctest expects.
|
||||
self.runner.run(self.dtest, out=failures) # type: ignore[arg-type] # noqa: F821
|
||||
self.runner.run(self.dtest, out=failures) # type: ignore[arg-type]
|
||||
if failures:
|
||||
raise MultipleDoctestFailures(failures)
|
||||
|
||||
@@ -302,7 +302,7 @@ class DoctestItem(pytest.Item):
|
||||
sys.stderr.write(err)
|
||||
|
||||
# TODO: Type ignored -- breaks Liskov Substitution.
|
||||
def repr_failure( # type: ignore[override] # noqa: F821
|
||||
def repr_failure( # type: ignore[override]
|
||||
self, excinfo: ExceptionInfo[BaseException],
|
||||
) -> Union[str, TerminalRepr]:
|
||||
import doctest
|
||||
@@ -329,7 +329,7 @@ class DoctestItem(pytest.Item):
|
||||
lineno = test.lineno + example.lineno + 1
|
||||
message = type(failure).__name__
|
||||
# TODO: ReprFileLocation doesn't expect a None lineno.
|
||||
reprlocation = ReprFileLocation(filename, lineno, message) # type: ignore[arg-type] # noqa: F821
|
||||
reprlocation = ReprFileLocation(filename, lineno, message) # type: ignore[arg-type]
|
||||
checker = _get_checker()
|
||||
report_choice = _get_report_choice(
|
||||
self.config.getoption("doctestreport")
|
||||
@@ -567,9 +567,9 @@ def _setup_fixtures(doctest_item: DoctestItem) -> FixtureRequest:
|
||||
def func() -> None:
|
||||
pass
|
||||
|
||||
doctest_item.funcargs = {} # type: ignore[attr-defined] # noqa: F821
|
||||
doctest_item.funcargs = {} # type: ignore[attr-defined]
|
||||
fm = doctest_item.session._fixturemanager
|
||||
doctest_item._fixtureinfo = fm.getfixtureinfo( # type: ignore[attr-defined] # noqa: F821
|
||||
doctest_item._fixtureinfo = fm.getfixtureinfo( # type: ignore[attr-defined]
|
||||
node=doctest_item, func=func, cls=None, funcargs=False
|
||||
)
|
||||
fixture_request = FixtureRequest(doctest_item)
|
||||
|
||||
@@ -248,7 +248,7 @@ def get_parametrized_fixture_keys(item: "nodes.Item", scopenum: int) -> Iterator
|
||||
the specified scope. """
|
||||
assert scopenum < scopenum_function # function
|
||||
try:
|
||||
callspec = item.callspec # type: ignore[attr-defined] # noqa: F821
|
||||
callspec = item.callspec # type: ignore[attr-defined]
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
@@ -266,7 +266,7 @@ def get_parametrized_fixture_keys(item: "nodes.Item", scopenum: int) -> Iterator
|
||||
elif scopenum == 2: # module
|
||||
key = (argname, param_index, item.fspath)
|
||||
elif scopenum == 3: # class
|
||||
item_cls = item.cls # type: ignore[attr-defined] # noqa: F821
|
||||
item_cls = item.cls # type: ignore[attr-defined]
|
||||
key = (argname, param_index, item.fspath, item_cls)
|
||||
yield key
|
||||
|
||||
@@ -477,7 +477,7 @@ class FixtureRequest:
|
||||
fixturedefs = self._fixturemanager.getfixturedefs(argname, parentid)
|
||||
# TODO: Fix this type ignore. Either add assert or adjust types.
|
||||
# Can this be None here?
|
||||
self._arg2fixturedefs[argname] = fixturedefs # type: ignore[assignment] # noqa: F821
|
||||
self._arg2fixturedefs[argname] = fixturedefs # type: ignore[assignment]
|
||||
# fixturedefs list is immutable so we maintain a decreasing index
|
||||
index = self._arg2index.get(argname, 0) - 1
|
||||
if fixturedefs is None or (-index > len(fixturedefs)):
|
||||
@@ -723,7 +723,7 @@ class FixtureRequest:
|
||||
if scope == "package":
|
||||
# FIXME: _fixturedef is not defined on FixtureRequest (this class),
|
||||
# but on FixtureRequest (a subclass).
|
||||
node = get_scope_package(self._pyfuncitem, self._fixturedef) # type: ignore[attr-defined] # noqa: F821
|
||||
node = get_scope_package(self._pyfuncitem, self._fixturedef) # type: ignore[attr-defined]
|
||||
else:
|
||||
node = get_scope_node(self._pyfuncitem, scope)
|
||||
if node is None and scope == "class":
|
||||
@@ -944,7 +944,7 @@ def _eval_scope_callable(
|
||||
try:
|
||||
# Type ignored because there is no typing mechanism to specify
|
||||
# keyword arguments, currently.
|
||||
result = scope_callable(fixture_name=fixture_name, config=config) # type: ignore[call-arg] # noqa: F821
|
||||
result = scope_callable(fixture_name=fixture_name, config=config) # type: ignore[call-arg]
|
||||
except Exception as e:
|
||||
raise TypeError(
|
||||
"Error evaluating {} while defining fixture '{}'.\n"
|
||||
@@ -1081,7 +1081,7 @@ def resolve_fixture_function(
|
||||
if fixturedef.unittest:
|
||||
if request.instance is not None:
|
||||
# bind the unbound method to the TestCase instance
|
||||
fixturefunc = fixturedef.func.__get__(request.instance) # type: ignore[union-attr] # noqa: F821
|
||||
fixturefunc = fixturedef.func.__get__(request.instance) # type: ignore[union-attr]
|
||||
else:
|
||||
# the fixture function needs to be bound to the actual
|
||||
# request.instance so that code working with "fixturedef" behaves
|
||||
@@ -1090,12 +1090,12 @@ def resolve_fixture_function(
|
||||
# handle the case where fixture is defined not in a test class, but some other class
|
||||
# (for example a plugin class with a fixture), see #2270
|
||||
if hasattr(fixturefunc, "__self__") and not isinstance(
|
||||
request.instance, fixturefunc.__self__.__class__ # type: ignore[union-attr] # noqa: F821
|
||||
request.instance, fixturefunc.__self__.__class__ # type: ignore[union-attr]
|
||||
):
|
||||
return fixturefunc
|
||||
fixturefunc = getimfunc(fixturedef.func)
|
||||
if fixturefunc != fixturedef.func:
|
||||
fixturefunc = fixturefunc.__get__(request.instance) # type: ignore[union-attr] # noqa: F821
|
||||
fixturefunc = fixturefunc.__get__(request.instance) # type: ignore[union-attr]
|
||||
return fixturefunc
|
||||
|
||||
|
||||
@@ -1167,7 +1167,7 @@ def wrap_function_to_error_out_if_called_directly(function, fixture_marker):
|
||||
|
||||
# keep reference to the original function in our own custom attribute so we don't unwrap
|
||||
# further than this point and lose useful wrappings like @mock.patch (#3774)
|
||||
result.__pytest_wrapped__ = _PytestWrapper(function) # type: ignore[attr-defined] # noqa: F821
|
||||
result.__pytest_wrapped__ = _PytestWrapper(function) # type: ignore[attr-defined]
|
||||
|
||||
return result
|
||||
|
||||
@@ -1209,7 +1209,7 @@ class FixtureFunctionMarker:
|
||||
)
|
||||
|
||||
# Type ignored because https://github.com/python/mypy/issues/2087.
|
||||
function._pytestfixturefunction = self # type: ignore[attr-defined] # noqa: F821
|
||||
function._pytestfixturefunction = self # type: ignore[attr-defined]
|
||||
return function
|
||||
|
||||
|
||||
@@ -1503,7 +1503,7 @@ class FixtureManager:
|
||||
def pytest_plugin_registered(self, plugin: _PluggyPlugin) -> None:
|
||||
nodeid = None
|
||||
try:
|
||||
p = py.path.local(plugin.__file__) # type: ignore[attr-defined] # noqa: F821
|
||||
p = py.path.local(plugin.__file__) # type: ignore[attr-defined]
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
|
||||
@@ -281,7 +281,7 @@ class _NodeReporter:
|
||||
self.__dict__.clear()
|
||||
# Type ignored becuase mypy doesn't like overriding a method.
|
||||
# Also the return value doesn't match...
|
||||
self.to_xml = lambda: py.xml.raw(data) # type: ignore # noqa: F821
|
||||
self.to_xml = lambda: py.xml.raw(data) # type: ignore
|
||||
|
||||
|
||||
def _warn_incompatibility_with_xunit2(
|
||||
|
||||
@@ -165,7 +165,7 @@ class PercentStyleMultiline(logging.PercentStyle):
|
||||
if "\n" in record.message:
|
||||
if hasattr(record, "auto_indent"):
|
||||
# passed in from the "extra={}" kwarg on the call to logging.log()
|
||||
auto_indent = self._get_auto_indent(record.auto_indent) # type: ignore[attr-defined] # noqa: F821
|
||||
auto_indent = self._get_auto_indent(record.auto_indent) # type: ignore[attr-defined]
|
||||
else:
|
||||
auto_indent = self._auto_indent
|
||||
|
||||
@@ -755,7 +755,7 @@ class _LiveLoggingStreamHandler(logging.StreamHandler):
|
||||
:param _pytest.terminal.TerminalReporter terminal_reporter:
|
||||
:param _pytest.capture.CaptureManager capture_manager:
|
||||
"""
|
||||
logging.StreamHandler.__init__(self, stream=terminal_reporter) # type: ignore[arg-type] # noqa: F821
|
||||
logging.StreamHandler.__init__(self, stream=terminal_reporter) # type: ignore[arg-type]
|
||||
self.capture_manager = capture_manager
|
||||
self.reset()
|
||||
self.set_when(None)
|
||||
|
||||
@@ -124,7 +124,7 @@ class ParameterSet(
|
||||
#
|
||||
# @pytest.mark.parametrize(('x', 'y'), [1, 2])
|
||||
# def test_foo(x, y): pass
|
||||
return cls(parameterset, marks=[], id=None) # type: ignore[arg-type] # noqa: F821
|
||||
return cls(parameterset, marks=[], id=None) # type: ignore[arg-type]
|
||||
|
||||
@staticmethod
|
||||
def _parse_parametrize_args(
|
||||
@@ -320,7 +320,7 @@ class MarkDecorator:
|
||||
# return type. Not much we can do about that. Thankfully mypy picks
|
||||
# the first match so it works out even if we break the rules.
|
||||
@overload
|
||||
def __call__(self, arg: _Markable) -> _Markable: # type: ignore[misc] # noqa: F821
|
||||
def __call__(self, arg: _Markable) -> _Markable: # type: ignore[misc]
|
||||
raise NotImplementedError()
|
||||
|
||||
@overload # noqa: F811
|
||||
|
||||
@@ -457,7 +457,7 @@ class Collector(Node):
|
||||
raise NotImplementedError("abstract")
|
||||
|
||||
# TODO: This omits the style= parameter which breaks Liskov Substitution.
|
||||
def repr_failure( # type: ignore[override] # noqa: F821
|
||||
def repr_failure( # type: ignore[override]
|
||||
self, excinfo: ExceptionInfo[BaseException]
|
||||
) -> Union[str, TerminalRepr]:
|
||||
"""
|
||||
@@ -600,7 +600,7 @@ class FSCollector(Collector):
|
||||
else:
|
||||
duplicate_paths.add(path)
|
||||
|
||||
return ihook.pytest_collect_file(path=path, parent=self) # type: ignore[no-any-return] # noqa: F723
|
||||
return ihook.pytest_collect_file(path=path, parent=self) # type: ignore[no-any-return]
|
||||
|
||||
|
||||
class File(FSCollector):
|
||||
|
||||
@@ -299,7 +299,7 @@ class PyobjMixin:
|
||||
"""Gets the underlying Python object. May be overwritten by subclasses."""
|
||||
# TODO: Improve the type of `parent` such that assert/ignore aren't needed.
|
||||
assert self.parent is not None
|
||||
obj = self.parent.obj # type: ignore[attr-defined] # noqa: F821
|
||||
obj = self.parent.obj # type: ignore[attr-defined]
|
||||
return getattr(obj, self.name)
|
||||
|
||||
def getmodpath(self, stopatmodule: bool = True, includemodule: bool = False) -> str:
|
||||
@@ -784,7 +784,7 @@ class Instance(PyCollector):
|
||||
def _getobj(self):
|
||||
# TODO: Improve the type of `parent` such that assert/ignore aren't needed.
|
||||
assert self.parent is not None
|
||||
obj = self.parent.obj # type: ignore[attr-defined] # noqa: F821
|
||||
obj = self.parent.obj # type: ignore[attr-defined]
|
||||
return obj()
|
||||
|
||||
def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]:
|
||||
@@ -1593,7 +1593,7 @@ class Function(PyobjMixin, nodes.Item):
|
||||
entry.set_repr_style("short")
|
||||
|
||||
# TODO: Type ignored -- breaks Liskov Substitution.
|
||||
def repr_failure( # type: ignore[override] # noqa: F821
|
||||
def repr_failure( # type: ignore[override]
|
||||
self, excinfo: ExceptionInfo[BaseException],
|
||||
) -> Union[str, TerminalRepr]:
|
||||
style = self.config.getoption("tbstyle", "auto")
|
||||
|
||||
@@ -165,7 +165,7 @@ class WarningsRecorder(warnings.catch_warnings):
|
||||
|
||||
def __init__(self) -> None:
|
||||
# Type ignored due to the way typeshed handles warnings.catch_warnings.
|
||||
super().__init__(record=True) # type: ignore[call-arg] # noqa: F821
|
||||
super().__init__(record=True) # type: ignore[call-arg]
|
||||
self._entered = False
|
||||
self._list = [] # type: List[warnings.WarningMessage]
|
||||
|
||||
|
||||
@@ -106,8 +106,8 @@ def runtestprotocol(
|
||||
item: Item, log: bool = True, nextitem: Optional[Item] = None
|
||||
) -> List[TestReport]:
|
||||
hasrequest = hasattr(item, "_request")
|
||||
if hasrequest and not item._request: # type: ignore[attr-defined] # noqa: F821
|
||||
item._initrequest() # type: ignore[attr-defined] # noqa: F821
|
||||
if hasrequest and not item._request: # type: ignore[attr-defined]
|
||||
item._initrequest() # type: ignore[attr-defined]
|
||||
rep = call_and_report(item, "setup", log)
|
||||
reports = [rep]
|
||||
if rep.passed:
|
||||
@@ -119,8 +119,8 @@ def runtestprotocol(
|
||||
# after all teardown hooks have been called
|
||||
# want funcargs and request info to go away
|
||||
if hasrequest:
|
||||
item._request = False # type: ignore[attr-defined] # noqa: F821
|
||||
item.funcargs = None # type: ignore[attr-defined] # noqa: F821
|
||||
item._request = False # type: ignore[attr-defined]
|
||||
item.funcargs = None # type: ignore[attr-defined]
|
||||
return reports
|
||||
|
||||
|
||||
@@ -422,7 +422,7 @@ class SetupState:
|
||||
# check if the last collection node has raised an error
|
||||
for col in self.stack:
|
||||
if hasattr(col, "_prepare_exc"):
|
||||
exc = col._prepare_exc # type: ignore[attr-defined] # noqa: F821
|
||||
exc = col._prepare_exc # type: ignore[attr-defined]
|
||||
raise exc
|
||||
|
||||
needed_collectors = colitem.listchain()
|
||||
@@ -431,7 +431,7 @@ class SetupState:
|
||||
try:
|
||||
col.setup()
|
||||
except TEST_OUTCOME as e:
|
||||
col._prepare_exc = e # type: ignore[attr-defined] # noqa: F821
|
||||
col._prepare_exc = e # type: ignore[attr-defined]
|
||||
raise e
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ def pytest_fixture_setup(
|
||||
param = fixturedef.ids[request.param_index]
|
||||
else:
|
||||
param = request.param
|
||||
fixturedef.cached_param = param # type: ignore[attr-defined] # noqa: F821
|
||||
fixturedef.cached_param = param # type: ignore[attr-defined]
|
||||
_show_fixture_action(fixturedef, "SETUP")
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ def pytest_fixture_post_finalizer(fixturedef: FixtureDef) -> None:
|
||||
if config.option.setupshow:
|
||||
_show_fixture_action(fixturedef, "TEARDOWN")
|
||||
if hasattr(fixturedef, "cached_param"):
|
||||
del fixturedef.cached_param # type: ignore[attr-defined] # noqa: F821
|
||||
del fixturedef.cached_param # type: ignore[attr-defined]
|
||||
|
||||
|
||||
def _show_fixture_action(fixturedef: FixtureDef, msg: str) -> None:
|
||||
|
||||
@@ -56,7 +56,7 @@ def pytest_configure(config: Config) -> None:
|
||||
def nop(*args, **kwargs):
|
||||
pass
|
||||
|
||||
nop.Exception = xfail.Exception # type: ignore[attr-defined] # noqa: F821
|
||||
nop.Exception = xfail.Exception # type: ignore[attr-defined]
|
||||
setattr(pytest, "xfail", nop)
|
||||
|
||||
config.addinivalue_line(
|
||||
|
||||
@@ -1219,7 +1219,7 @@ def _get_line_with_reprcrash_message(
|
||||
|
||||
try:
|
||||
# Type ignored intentionally -- possible AttributeError expected.
|
||||
msg = rep.longrepr.reprcrash.message # type: ignore[union-attr] # noqa: F821
|
||||
msg = rep.longrepr.reprcrash.message # type: ignore[union-attr]
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
|
||||
@@ -102,13 +102,13 @@ class UnitTestCase(Class):
|
||||
cls, "setUpClass", "tearDownClass", scope="class", pass_self=False
|
||||
)
|
||||
if class_fixture:
|
||||
cls.__pytest_class_setup = class_fixture # type: ignore[attr-defined] # noqa: F821
|
||||
cls.__pytest_class_setup = class_fixture # type: ignore[attr-defined]
|
||||
|
||||
method_fixture = _make_xunit_fixture(
|
||||
cls, "setup_method", "teardown_method", scope="function", pass_self=True
|
||||
)
|
||||
if method_fixture:
|
||||
cls.__pytest_method_setup = method_fixture # type: ignore[attr-defined] # noqa: F821
|
||||
cls.__pytest_method_setup = method_fixture # type: ignore[attr-defined]
|
||||
|
||||
|
||||
def _make_xunit_fixture(
|
||||
@@ -148,7 +148,7 @@ class TestCaseFunction(Function):
|
||||
# a bound method to be called during teardown() if set (see 'runtest()')
|
||||
self._explicit_tearDown = None # type: Optional[Callable[[], None]]
|
||||
assert self.parent is not None
|
||||
self._testcase = self.parent.obj(self.name) # type: ignore[attr-defined] # noqa: F821
|
||||
self._testcase = self.parent.obj(self.name) # type: ignore[attr-defined]
|
||||
self._obj = getattr(self._testcase, self.name)
|
||||
if hasattr(self, "_request"):
|
||||
self._request._fillfixtures()
|
||||
@@ -167,7 +167,7 @@ class TestCaseFunction(Function):
|
||||
# unwrap potential exception info (see twisted trial support below)
|
||||
rawexcinfo = getattr(rawexcinfo, "_rawexcinfo", rawexcinfo)
|
||||
try:
|
||||
excinfo = _pytest._code.ExceptionInfo(rawexcinfo) # type: ignore[arg-type] # noqa: F821
|
||||
excinfo = _pytest._code.ExceptionInfo(rawexcinfo) # type: ignore[arg-type]
|
||||
# invoke the attributes to trigger storing the traceback
|
||||
# trial causes some issue there
|
||||
excinfo.value
|
||||
@@ -259,7 +259,7 @@ class TestCaseFunction(Function):
|
||||
# let the unittest framework handle async functions
|
||||
if is_async_function(self.obj):
|
||||
# Type ignored because self acts as the TestResult, but is not actually one.
|
||||
self._testcase(result=self) # type: ignore[arg-type] # noqa: F821
|
||||
self._testcase(result=self) # type: ignore[arg-type]
|
||||
else:
|
||||
# when --pdb is given, we want to postpone calling tearDown() otherwise
|
||||
# when entering the pdb prompt, tearDown() would have probably cleaned up
|
||||
@@ -275,7 +275,7 @@ class TestCaseFunction(Function):
|
||||
# wrap_pytest_function_for_tracing replaces self.obj by a wrapper
|
||||
setattr(self._testcase, self.name, self.obj)
|
||||
try:
|
||||
self._testcase(result=self) # type: ignore[arg-type] # noqa: F821
|
||||
self._testcase(result=self) # type: ignore[arg-type]
|
||||
finally:
|
||||
delattr(self._testcase, self.name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user