From b8a20d63646b3a9d45def91279a2c3efd3ee7c0e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:01:09 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks.git: v4.6.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks.git/compare/v4.6.0...v5.0.0) - [github.com/python-jsonschema/check-jsonschema: 0.29.2 → 0.30.0](https://github.com/python-jsonschema/check-jsonschema/compare/0.29.2...0.30.0) - [github.com/psf/black: 24.8.0 → 24.10.0](https://github.com/psf/black/compare/24.8.0...24.10.0) - [github.com/asottile/pyupgrade: v3.17.0 → v3.19.0](https://github.com/asottile/pyupgrade/compare/v3.17.0...v3.19.0) - [github.com/sirosen/slyp: 0.7.1 → 0.8.1](https://github.com/sirosen/slyp/compare/0.7.1...0.8.1) - [github.com/tox-dev/pyproject-fmt: 2.2.3 → v2.5.0](https://github.com/tox-dev/pyproject-fmt/compare/2.2.3...v2.5.0) --- .pre-commit-config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f74d70d8..6007b676 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks.git - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-merge-conflict - id: check-toml @@ -8,13 +8,13 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.29.2 + rev: 0.30.0 hooks: - id: check-github-workflows - id: check-dependabot - id: check-readthedocs - repo: https://github.com/psf/black - rev: 24.8.0 + rev: 24.10.0 hooks: - id: black language_version: python3 @@ -23,7 +23,7 @@ repos: hooks: - id: isort - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 + rev: v3.19.0 hooks: - id: pyupgrade args: ["--py37-plus"] @@ -36,7 +36,7 @@ repos: - 'flake8-comprehensions==3.14.0' - 'flake8-typing-as-t==0.0.3' - repo: https://github.com/sirosen/slyp - rev: 0.7.1 + rev: 0.8.1 hooks: - id: slyp - repo: https://github.com/codespell-project/codespell @@ -49,7 +49,7 @@ repos: - "-L" - "assertIn" - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.2.3 + rev: v2.5.0 hooks: - id: pyproject-fmt additional_dependencies: ["tox>=4.9"] From f3009256517b4639d5da1a3d623c057dd6c9bfa7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:01:36 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nose2/config.py | 2 +- nose2/events.py | 74 +++++++++---------- nose2/loader.py | 2 +- nose2/main.py | 2 +- nose2/plugins/attrib.py | 4 +- nose2/plugins/buffer.py | 4 +- nose2/plugins/coverage.py | 2 +- nose2/plugins/debugger.py | 2 +- nose2/plugins/doctests.py | 2 +- nose2/plugins/junitxml.py | 2 +- nose2/plugins/layers.py | 2 +- nose2/plugins/loader/discovery.py | 2 +- nose2/plugins/loader/generators.py | 2 +- nose2/plugins/loader/parameters.py | 2 +- nose2/plugins/loader/testclasses.py | 2 +- nose2/plugins/logcapture.py | 6 +- nose2/plugins/mp.py | 10 +-- nose2/plugins/outcomes.py | 2 +- nose2/plugins/prettyassert.py | 2 +- nose2/plugins/prof.py | 2 +- nose2/plugins/result.py | 2 +- nose2/plugins/testid.py | 2 +- nose2/result.py | 2 +- nose2/runner.py | 2 +- nose2/session.py | 2 +- nose2/sphinxext.py | 6 +- nose2/suite.py | 2 +- nose2/tests/_common.py | 18 ++--- .../tests/functional/support/lib/plugin_a.py | 2 +- .../test_class_fail/test_class_fail.py | 2 +- .../tests/functional/test_discovery_loader.py | 2 +- nose2/tests/functional/test_util.py | 2 +- nose2/tests/unit/test_buffer_plugin.py | 2 +- nose2/tests/unit/test_debugger_plugin.py | 2 +- nose2/tests/unit/test_loader.py | 2 +- nose2/tests/unit/test_logcapture_plugin.py | 4 +- nose2/tests/unit/test_outcomes_plugin.py | 2 +- nose2/tests/unit/test_printhooks_plugin.py | 2 +- nose2/tests/unit/test_testclass_loader.py | 2 +- nose2/tools/such.py | 6 +- nose2/util.py | 2 +- pyproject.toml | 1 + 42 files changed, 99 insertions(+), 98 deletions(-) diff --git a/nose2/config.py b/nose2/config.py index 8df02257..1b407e7e 100644 --- a/nose2/config.py +++ b/nose2/config.py @@ -11,7 +11,7 @@ class Config: """ - def __init__(self, items): + def __init__(self, items) -> None: self._items = items self._mvd = {} for k, v in items: diff --git a/nose2/events.py b/nose2/events.py index 272880e4..06969709 100644 --- a/nose2/events.py +++ b/nose2/events.py @@ -224,7 +224,7 @@ class Hook: """ - def __init__(self, method): + def __init__(self, method) -> None: self.method = method self.plugins = [] @@ -319,7 +319,7 @@ class PluginInterface: ) hookClass: type[Hook] = Hook - def __init__(self): + def __init__(self) -> None: self.hooks = {} def addMethod(self, method): @@ -367,7 +367,7 @@ class Event: _attrs: t.ClassVar[tuple[str, ...]] = ("handled",) version = "0.4" - def __init__(self, **metadata): + def __init__(self, **metadata) -> None: self.handled = False self.metadata = {} self.metadata.update(metadata) @@ -413,7 +413,7 @@ class PluginsLoadedEvent(Event): _attrs = Event._attrs + ("pluginsLoaded",) - def __init__(self, pluginsLoaded, **kw): + def __init__(self, pluginsLoaded, **kw) -> None: self.pluginsLoaded = pluginsLoaded super().__init__(**kw) @@ -430,7 +430,7 @@ class RunnerCreatedEvent(Event): _attrs = Event._attrs + ("runner",) - def __init__(self, runner, **kw): + def __init__(self, runner, **kw) -> None: self.runner = runner super().__init__(**kw) @@ -447,7 +447,7 @@ class ResultCreatedEvent(Event): _attrs = Event._attrs + ("result",) - def __init__(self, result, **kw): + def __init__(self, result, **kw) -> None: self.result = result super().__init__(**kw) @@ -462,7 +462,7 @@ class StartLayerSetupEvent(Event): _attrs = Event._attrs + ("layer",) - def __init__(self, layer, **kw): + def __init__(self, layer, **kw) -> None: self.layer = layer super().__init__(**kw) @@ -477,7 +477,7 @@ class StopLayerSetupEvent(Event): _attrs = Event._attrs + ("layer",) - def __init__(self, layer, **kw): + def __init__(self, layer, **kw) -> None: self.layer = layer super().__init__(**kw) @@ -496,7 +496,7 @@ class StartLayerSetupTestEvent(Event): _attrs = Event._attrs + ("layer", "test") - def __init__(self, layer, test, **kw): + def __init__(self, layer, test, **kw) -> None: self.layer = layer self.test = test super().__init__(**kw) @@ -516,7 +516,7 @@ class StopLayerSetupTestEvent(Event): _attrs = Event._attrs + ("layer", "test") - def __init__(self, layer, test, **kw): + def __init__(self, layer, test, **kw) -> None: self.layer = layer self.test = test super().__init__(**kw) @@ -532,7 +532,7 @@ class StartLayerTeardownEvent(Event): _attrs = Event._attrs + ("layer",) - def __init__(self, layer, **kw): + def __init__(self, layer, **kw) -> None: self.layer = layer super().__init__(**kw) @@ -547,7 +547,7 @@ class StopLayerTeardownEvent(Event): _attrs = Event._attrs + ("layer",) - def __init__(self, layer, **kw): + def __init__(self, layer, **kw) -> None: self.layer = layer super().__init__(**kw) @@ -566,7 +566,7 @@ class StartLayerTeardownTestEvent(Event): _attrs = Event._attrs + ("layer", "test") - def __init__(self, layer, test, **kw): + def __init__(self, layer, test, **kw) -> None: self.layer = layer self.test = test super().__init__(**kw) @@ -586,7 +586,7 @@ class StopLayerTeardownTestEvent(Event): _attrs = Event._attrs + ("layer", "test") - def __init__(self, layer, test, **kw): + def __init__(self, layer, test, **kw) -> None: self.layer = layer self.test = test super().__init__(**kw) @@ -633,7 +633,7 @@ def execute(suite, result): _attrs = Event._attrs + ("runner", "suite", "result", "startTime", "executeTests") - def __init__(self, runner, suite, result, startTime, executeTests, **kw): + def __init__(self, runner, suite, result, startTime, executeTests, **kw) -> None: self.suite = suite self.runner = runner self.result = result @@ -665,7 +665,7 @@ class StopTestRunEvent(Event): _attrs = Event._attrs + ("runner", "result", "stopTime", "timeTaken") - def __init__(self, runner, result, stopTime, timeTaken, **kw): + def __init__(self, runner, result, stopTime, timeTaken, **kw) -> None: self.runner = runner self.result = result self.stopTime = stopTime @@ -692,7 +692,7 @@ class StartTestEvent(Event): _attrs = Event._attrs + ("test", "result", "startTime") - def __init__(self, test, result, startTime, **kw): + def __init__(self, test, result, startTime, **kw) -> None: self.test = test self.result = result self.startTime = startTime @@ -718,7 +718,7 @@ class StopTestEvent(Event): _attrs = Event._attrs + ("test", "result", "stopTime") - def __init__(self, test, result, stopTime, **kw): + def __init__(self, test, result, stopTime, **kw) -> None: self.test = test self.result = result self.stopTime = stopTime @@ -799,7 +799,7 @@ def __init__( shortLabel=None, longLabel=None, **kw, - ): + ) -> None: self.test = test self.result = result self.outcome = outcome @@ -837,7 +837,7 @@ class LoadFromModuleEvent(Event): _attrs = Event._attrs + ("loader", "module", "extraTests") - def __init__(self, loader, module, **kw): + def __init__(self, loader, module, **kw) -> None: self.loader = loader self.module = module self.extraTests = [] @@ -847,7 +847,7 @@ def __init__(self, loader, module, **kw): class ModuleSuiteEvent(Event): _attrs = Event._attrs + ("loader", "module", "suite") - def __init__(self, loader, module, suite, **kw): + def __init__(self, loader, module, suite, **kw) -> None: self.loader = loader self.module = module self.suite = suite @@ -880,7 +880,7 @@ class LoadFromTestCaseEvent(Event): _attrs = Event._attrs + ("loader", "testCase", "extraTests") - def __init__(self, loader, testCase, **kw): + def __init__(self, loader, testCase, **kw) -> None: self.loader = loader self.testCase = testCase self.extraTests = [] @@ -918,7 +918,7 @@ class LoadFromNamesEvent(Event): _attrs = Event._attrs + ("loader", "names", "module", "extraTests") - def __init__(self, loader, names, module, **kw): + def __init__(self, loader, names, module, **kw) -> None: self.loader = loader self.names = names self.module = module @@ -960,7 +960,7 @@ class LoadFromNameEvent(Event): _attrs = Event._attrs + ("loader", "name", "module", "extraTests") - def __init__(self, loader, name, module, **kw): + def __init__(self, loader, name, module, **kw) -> None: self.loader = loader self.name = name self.module = module @@ -1012,7 +1012,7 @@ class HandleFileEvent(Event): _attrs = Event._attrs + ("loader", "name", "path", "pattern", "topLevelDirectory") - def __init__(self, loader, name, path, pattern, topLevelDirectory, **kw): + def __init__(self, loader, name, path, pattern, topLevelDirectory, **kw) -> None: self.extraTests = [] self.path = path self.loader = loader @@ -1046,7 +1046,7 @@ class MatchPathEvent(Event): _attrs = Event._attrs + ("name", "path", "pattern") - def __init__(self, name, path, pattern, **kw): + def __init__(self, name, path, pattern, **kw) -> None: self.path = path self.name = name self.pattern = pattern @@ -1101,7 +1101,7 @@ class GetTestCaseNamesEvent(Event): "isTestMethod", ) - def __init__(self, loader, testCase, isTestMethod, **kw): + def __init__(self, loader, testCase, isTestMethod, **kw) -> None: self.loader = loader self.testCase = testCase self.testMethodPrefix = None @@ -1134,7 +1134,7 @@ class ResultSuccessEvent(Event): _attrs = Event._attrs + ("result", "success") - def __init__(self, result, success, **kw): + def __init__(self, result, success, **kw) -> None: self.result = result self.success = success super().__init__(**kw) @@ -1158,7 +1158,7 @@ class ResultStopEvent(Event): _attrs = Event._attrs + ("result", "shouldStop") - def __init__(self, result, shouldStop, **kw): + def __init__(self, result, shouldStop, **kw) -> None: self.result = result self.shouldStop = shouldStop super().__init__(**kw) @@ -1185,7 +1185,7 @@ class DescribeTestEvent(Event): _attrs = Event._attrs + ("test", "description") - def __init__(self, test, description=None, errorList=False, **kw): + def __init__(self, test, description=None, errorList=False, **kw) -> None: self.test = test self.description = description self.errorList = errorList @@ -1210,7 +1210,7 @@ class OutcomeDetailEvent(Event): _attrs = Event._attrs + ("outcomeEvent", "extraDetail") - def __init__(self, outcomeEvent, **kw): + def __init__(self, outcomeEvent, **kw) -> None: self.outcomeEvent = outcomeEvent self.extraDetail = [] super().__init__(**kw) @@ -1239,7 +1239,7 @@ class ReportSummaryEvent(Event): _attrs = Event._attrs + ("stopTestEvent", "stream", "reportCategories") - def __init__(self, stopTestEvent, stream, reportCategories, **kw): + def __init__(self, stopTestEvent, stream, reportCategories, **kw) -> None: self.stopTestEvent = stopTestEvent self.stream = stream self.reportCategories = reportCategories @@ -1266,7 +1266,7 @@ class ReportTestEvent(Event): _attrs = Event._attrs + ("testEvent", "stream") - def __init__(self, testEvent, stream, **kw): + def __init__(self, testEvent, stream, **kw) -> None: self.testEvent = testEvent self.stream = stream super().__init__(**kw) @@ -1284,7 +1284,7 @@ class UserInteractionEvent(Event): """ - def __init__(self, **kw): + def __init__(self, **kw) -> None: super().__init__(**kw) @@ -1308,7 +1308,7 @@ class CommandLineArgsEvent(Event): _attrs = Event._attrs + ("args",) - def __init__(self, args, **kw): + def __init__(self, args, **kw) -> None: self.args = args super().__init__(**kw) @@ -1336,7 +1336,7 @@ class CreateTestsEvent(Event): _attrs = Event._attrs + ("loader", "testNames", "module") - def __init__(self, loader, testNames, module, **kw): + def __init__(self, loader, testNames, module, **kw) -> None: self.loader = loader self.testNames = testNames self.module = module @@ -1357,6 +1357,6 @@ class CreatedTestSuiteEvent(Event): _attrs = Event._attrs + ("suite",) - def __init__(self, suite, **kw): + def __init__(self, suite, **kw) -> None: self.suite = suite super().__init__(**kw) diff --git a/nose2/loader.py b/nose2/loader.py index c41464fc..460464a3 100644 --- a/nose2/loader.py +++ b/nose2/loader.py @@ -27,7 +27,7 @@ class PluggableTestLoader: suiteClass = unittest.TestSuite - def __init__(self, session): + def __init__(self, session) -> None: self.session = session def loadTestsFromModule(self, module): diff --git a/nose2/main.py b/nose2/main.py index 08b3cedb..dbb834fa 100644 --- a/nose2/main.py +++ b/nose2/main.py @@ -75,7 +75,7 @@ class PluggableTestProgram(unittest.TestProgram): excludePlugins = () # XXX override __init__ to warn that testLoader and testRunner are ignored? - def __init__(self, **kw): + def __init__(self, **kw) -> None: plugins = kw.pop("plugins", []) exclude = kw.pop("excludePlugins", []) hooks = kw.pop("extraHooks", []) diff --git a/nose2/plugins/attrib.py b/nose2/plugins/attrib.py index c117da92..caca3125 100644 --- a/nose2/plugins/attrib.py +++ b/nose2/plugins/attrib.py @@ -10,7 +10,7 @@ class AttributeSelector(Plugin): """Filter tests by attribute""" - def __init__(self): + def __init__(self) -> None: self.attribs = [] self.eval_attribs = [] self.addArgument( @@ -154,7 +154,7 @@ def _get_attr(test, key): class ContextHelper: - def __init__(self, obj): + def __init__(self, obj) -> None: self.obj = obj def __getitem__(self, name): diff --git a/nose2/plugins/buffer.py b/nose2/plugins/buffer.py index a49585e9..bf397314 100644 --- a/nose2/plugins/buffer.py +++ b/nose2/plugins/buffer.py @@ -24,7 +24,7 @@ class _Buffer: - def __init__(self, stream): + def __init__(self, stream) -> None: self._stream = stream self._buffer = io.StringIO() @@ -56,7 +56,7 @@ class OutputBufferPlugin(events.Plugin): commandLineSwitch = ("B", "output-buffer", "Enable output buffer") configSection = "output-buffer" - def __init__(self): + def __init__(self) -> None: self.captureStdout = self.config.as_bool("stdout", default=True) self.captureStderr = self.config.as_bool("stderr", default=False) self.bufStdout = self.bufStderr = None diff --git a/nose2/plugins/coverage.py b/nose2/plugins/coverage.py index 77dba825..1a057c9d 100644 --- a/nose2/plugins/coverage.py +++ b/nose2/plugins/coverage.py @@ -43,7 +43,7 @@ class Coverage(Plugin): _mpmode = False _subprocess = False - def __init__(self): + def __init__(self) -> None: """Get our config and add our command line arguments.""" # tracking var for any decision which marks the entire run as failed self.decided_failure = False diff --git a/nose2/plugins/debugger.py b/nose2/plugins/debugger.py index c2a782e5..991649cf 100644 --- a/nose2/plugins/debugger.py +++ b/nose2/plugins/debugger.py @@ -35,7 +35,7 @@ class Debugger(events.Plugin): # allow easy mocking and replacement of pdb pdb = pdb - def __init__(self): + def __init__(self) -> None: self.errorsOnly = self.config.as_bool("errors-only", default=False) def testOutcome(self, event): diff --git a/nose2/plugins/doctests.py b/nose2/plugins/doctests.py index d644b07a..598133ae 100644 --- a/nose2/plugins/doctests.py +++ b/nose2/plugins/doctests.py @@ -30,7 +30,7 @@ class DocTestLoader(Plugin): "Load doctests from text files and modules", ) - def __init__(self): + def __init__(self) -> None: self.extensions = self.config.as_list("extensions", [".txt", ".rst"]) def handleFile(self, event): diff --git a/nose2/plugins/junitxml.py b/nose2/plugins/junitxml.py index bd3bbc19..dde98276 100644 --- a/nose2/plugins/junitxml.py +++ b/nose2/plugins/junitxml.py @@ -102,7 +102,7 @@ class JUnitXmlReporter(events.Plugin): configSection = "junit-xml" commandLineSwitch = ("X", "junit-xml", "Generate junit-xml output report") - def __init__(self): + def __init__(self) -> None: # Read argument from configuration file, or filled with default self.path = os.path.realpath( self.config.as_str("path", default="nose2-junit.xml") diff --git a/nose2/plugins/layers.py b/nose2/plugins/layers.py index 190b30ea..4166bc99 100644 --- a/nose2/plugins/layers.py +++ b/nose2/plugins/layers.py @@ -198,7 +198,7 @@ class LayerReporter(events.Plugin): ) configSection = "layer-reporter" - def __init__(self): + def __init__(self) -> None: self.indent = self.config.as_str("indent", " ") self.colors = self.config.as_bool("colors", False) self.highlight_words = self.config.as_list( diff --git a/nose2/plugins/loader/discovery.py b/nose2/plugins/loader/discovery.py index 24654ae8..ed2610a0 100644 --- a/nose2/plugins/loader/discovery.py +++ b/nose2/plugins/loader/discovery.py @@ -31,7 +31,7 @@ class DirectoryHandler: - def __init__(self, session): + def __init__(self, session) -> None: self.session = session self.event_handled = False diff --git a/nose2/plugins/loader/generators.py b/nose2/plugins/loader/generators.py index a367ec48..c38c69f2 100644 --- a/nose2/plugins/loader/generators.py +++ b/nose2/plugins/loader/generators.py @@ -228,7 +228,7 @@ def createTest(name): class GeneratorFunctionCase(unittest.FunctionTestCase): - def __init__(self, name, **args): + def __init__(self, name, **args) -> None: self._funcName = name unittest.FunctionTestCase.__init__(self, None, **args) diff --git a/nose2/plugins/loader/parameters.py b/nose2/plugins/loader/parameters.py index 4797faff..2e1ea4a1 100644 --- a/nose2/plugins/loader/parameters.py +++ b/nose2/plugins/loader/parameters.py @@ -56,7 +56,7 @@ def testExtraArg(case, bar, foo): class ParamsFunctionCase(unittest.FunctionTestCase): - def __init__(self, name, func, **args): + def __init__(self, name, func, **args) -> None: self._funcName = name unittest.FunctionTestCase.__init__(self, func, **args) diff --git a/nose2/plugins/loader/testclasses.py b/nose2/plugins/loader/testclasses.py index 3e98674e..49226863 100644 --- a/nose2/plugins/loader/testclasses.py +++ b/nose2/plugins/loader/testclasses.py @@ -194,7 +194,7 @@ def isTestMethod(attrname, cls=cls, excluded=excluded): # hide it inside of a factory func. ugly! def MethodTestCase(cls): class _MethodTestCase(unittest.TestCase): - def __init__(self, method): + def __init__(self, method) -> None: self.method = method self._name = f"{cls.__module__}.{cls.__name__}.{method}" self.obj = cls() diff --git a/nose2/plugins/logcapture.py b/nose2/plugins/logcapture.py index b019b058..8273021c 100644 --- a/nose2/plugins/logcapture.py +++ b/nose2/plugins/logcapture.py @@ -31,7 +31,7 @@ class LogCapture(Plugin): clear = False filters = ["-nose"] - def __init__(self): + def __init__(self) -> None: self.logformat = self.config.as_str("format", self.logformat) self.logdatefmt = self.config.as_str("date-format", self.logdatefmt) self.filters = self.config.as_list("filter", self.filters) @@ -104,7 +104,7 @@ def _addCapturedLogs(self, event): class FilterSet: - def __init__(self, filter_components): + def __init__(self, filter_components) -> None: self.inclusive, self.exclusive = self._partition(filter_components) @staticmethod @@ -146,7 +146,7 @@ def _deny(self, record): class MyMemoryHandler(BufferingHandler): - def __init__(self, capacity, logformat, logdatefmt, filters): + def __init__(self, capacity, logformat, logdatefmt, filters) -> None: BufferingHandler.__init__(self, capacity) fmt = logging.Formatter(logformat, logdatefmt) self.setFormatter(fmt) diff --git a/nose2/plugins/mp.py b/nose2/plugins/mp.py index f80b3930..0d02a40b 100644 --- a/nose2/plugins/mp.py +++ b/nose2/plugins/mp.py @@ -15,7 +15,7 @@ class MultiProcess(events.Plugin): configSection = "multiprocess" - def __init__(self): + def __init__(self) -> None: self.addArgument( self.setProcs, "N", @@ -433,7 +433,7 @@ def execute(suite, result): """ - def __init__(self, loader, result, runner, plugins, connection, **metadata): + def __init__(self, loader, result, runner, plugins, connection, **metadata) -> None: self.loader = loader self.result = result self.runner = runner @@ -457,14 +457,14 @@ def registerInSubprocess(self, event): """ - def __init__(self, **metadata): + def __init__(self, **metadata) -> None: self.pluginClasses = [] super().__init__(**metadata) # custom hook system that records calls and events class RecordingHook(events.Hook): - def __init__(self, method, interface): + def __init__(self, method, interface) -> None: super().__init__(method) self.interface = interface @@ -485,7 +485,7 @@ class RecordingPluginInterface(events.PluginInterface): "getTestMethodNames", } - def __init__(self): + def __init__(self) -> None: super().__init__() self.events = [] diff --git a/nose2/plugins/outcomes.py b/nose2/plugins/outcomes.py index 0a6dc89d..672d9751 100644 --- a/nose2/plugins/outcomes.py +++ b/nose2/plugins/outcomes.py @@ -33,7 +33,7 @@ class Outcomes(Plugin): "Treat some configured exceptions as failure or skips", ) - def __init__(self): + def __init__(self) -> None: self.treatAsFail = set(self.config.as_list("treat-as-fail", [])) self.treatAsSkip = set(self.config.as_list("treat-as-skip", [])) diff --git a/nose2/plugins/prettyassert.py b/nose2/plugins/prettyassert.py index d923f6ca..573e208c 100644 --- a/nose2/plugins/prettyassert.py +++ b/nose2/plugins/prettyassert.py @@ -245,7 +245,7 @@ def _tokenize_assert(source_lines, frame_locals, frame_globals): class TokenProcessor: - def __init__(self, frame_locals, frame_globals): + def __init__(self, frame_locals, frame_globals) -> None: # local and global variables from the frame which we're inspecting self.frame_locals, self.frame_globals = frame_locals, frame_globals diff --git a/nose2/plugins/prof.py b/nose2/plugins/prof.py index 4114cfe2..f8a5197d 100644 --- a/nose2/plugins/prof.py +++ b/nose2/plugins/prof.py @@ -32,7 +32,7 @@ class Profiler(events.Plugin): configSection = "profiler" commandLineSwitch = ("P", "profile", "Run tests under profiler") - def __init__(self): + def __init__(self) -> None: self.pfile = self.config.as_str("filename", "") self.sort = self.config.as_str("sort", "cumulative") self.restrict = self.config.as_list("restrict", []) diff --git a/nose2/plugins/result.py b/nose2/plugins/result.py index e13282d7..cab62d73 100644 --- a/nose2/plugins/result.py +++ b/nose2/plugins/result.py @@ -42,7 +42,7 @@ class ResultReporter(events.Plugin): separator1 = "=" * 70 separator2 = "-" * 70 - def __init__(self): + def __init__(self) -> None: self.testsRun = 0 self.reportCategories = { "failures": [], diff --git a/nose2/plugins/testid.py b/nose2/plugins/testid.py index 646bcb25..2655b3c8 100644 --- a/nose2/plugins/testid.py +++ b/nose2/plugins/testid.py @@ -28,7 +28,7 @@ class TestId(Plugin): commandLineSwitch = ("I", "with-id", "Add test ids to output") idpat = re.compile(r"(\d+)") - def __init__(self): + def __init__(self) -> None: self.idfile = self.config.as_str("id-file", ".noseids") self.ids = {} self.tests = {} diff --git a/nose2/result.py b/nose2/result.py index 4fd5e73d..1baf5423 100644 --- a/nose2/result.py +++ b/nose2/result.py @@ -25,7 +25,7 @@ class PluggableTestResult: """ - def __init__(self, session): + def __init__(self, session) -> None: self.session = session self.shouldStop = False # XXX TestCase.subTest expects a result.failfast attribute diff --git a/nose2/runner.py b/nose2/runner.py index 4790e897..532895b8 100644 --- a/nose2/runner.py +++ b/nose2/runner.py @@ -24,7 +24,7 @@ class PluggableTestRunner: resultClass = result.PluggableTestResult - def __init__(self, session): + def __init__(self, session) -> None: self.session = session def run(self, test): diff --git a/nose2/session.py b/nose2/session.py index d6e527eb..408b5c61 100644 --- a/nose2/session.py +++ b/nose2/session.py @@ -73,7 +73,7 @@ class Session: configClass = config.Config - def __init__(self): + def __init__(self) -> None: self.argparse = argparse.ArgumentParser(prog="nose2", add_help=False) self.pluginargs = self.argparse.add_argument_group( "plugin arguments", "Command-line arguments added by plugins:" diff --git a/nose2/sphinxext.py b/nose2/sphinxext.py index 4888fb66..26c83510 100644 --- a/nose2/sphinxext.py +++ b/nose2/sphinxext.py @@ -172,7 +172,7 @@ def setup(app): class ConfigBucket: - def __init__(self): + def __init__(self) -> None: self.section = None self.vars = {} @@ -218,7 +218,7 @@ def get(self, item, default=DEFAULT): class OptBucket: - def __init__(self, doc=None, prog="nosetests"): + def __init__(self, doc=None, prog="nosetests") -> None: self.seen = set() self.opts = [] self.doc = doc @@ -245,7 +245,7 @@ def __call__(self, callback, opt=None, longOpt=None, help=None): class Opt: - def __init__(self, *arg, **kw): + def __init__(self, *arg, **kw) -> None: self.opts = arg self.action = kw.pop("action", None) self.default = kw.pop("default", None) diff --git a/nose2/suite.py b/nose2/suite.py index 034c27e0..be04ef55 100644 --- a/nose2/suite.py +++ b/nose2/suite.py @@ -14,7 +14,7 @@ class LayerSuite(unittest.BaseTestSuite): - def __init__(self, session, tests=(), layer=None): + def __init__(self, session, tests=(), layer=None) -> None: super().__init__(tests) self.layer = layer self.wasSetup = False diff --git a/nose2/tests/_common.py b/nose2/tests/_common.py index c7b1f6ae..5cd40d7c 100644 --- a/nose2/tests/_common.py +++ b/nose2/tests/_common.py @@ -104,7 +104,7 @@ def runModuleAsMain(self, testmodule, *args): class _FakeEventBase: """Baseclass for fake :class:`~nose2.events.Event`s.""" - def __init__(self): + def __init__(self) -> None: self.handled = False self.version = "0.1" self.metadata = {} @@ -113,7 +113,7 @@ def __init__(self): class FakeHandleFileEvent(_FakeEventBase): """Fake HandleFileEvent.""" - def __init__(self, name): + def __init__(self, name) -> None: super().__init__() self.loader = Stub() # FIXME @@ -125,7 +125,7 @@ def __init__(self, name): class FakeStartTestEvent(_FakeEventBase): """Fake :class:`~nose2.events.StartTestEvent`.""" - def __init__(self, test): + def __init__(self, test) -> None: super().__init__() self.test = test self.result = test.defaultTestResult() @@ -137,7 +137,7 @@ def __init__(self, test): class FakeLoadFromNameEvent(_FakeEventBase): """Fake :class:`~nose2.events.LoadFromNameEvent`.""" - def __init__(self, name): + def __init__(self, name) -> None: super().__init__() self.name = name @@ -145,7 +145,7 @@ def __init__(self, name): class FakeLoadFromNamesEvent(_FakeEventBase): """Fake :class:`~nose2.events.LoadFromNamesEvent`.""" - def __init__(self, names): + def __init__(self, names) -> None: super().__init__() self.names = names @@ -155,7 +155,7 @@ class FakeStartTestRunEvent(_FakeEventBase): def __init__( self, runner=None, suite=None, result=None, startTime=None, executeTests=None - ): + ) -> None: super().__init__() self.suite = suite self.runner = runner @@ -197,7 +197,7 @@ def run_module_as_main(test_module, *args): class NotReallyAProc: - def __init__(self, args, cwd=None, **kwargs): + def __init__(self, args, cwd=None, **kwargs) -> None: self.args = args self.chdir = cwd self.kwargs = kwargs @@ -249,7 +249,7 @@ class RedirectStdStreams: buffers. """ - def __init__(self): + def __init__(self) -> None: self.stdout = io.StringIO() self.stderr = io.StringIO() @@ -269,7 +269,7 @@ def __exit__(self, exc_type, exc_value, traceback): # mock multiprocessing Connection class Conn: - def __init__(self, items): + def __init__(self, items) -> None: self.items = items self.sent = [] self.closed = False diff --git a/nose2/tests/functional/support/lib/plugin_a.py b/nose2/tests/functional/support/lib/plugin_a.py index f12cbc97..07a9d2a7 100644 --- a/nose2/tests/functional/support/lib/plugin_a.py +++ b/nose2/tests/functional/support/lib/plugin_a.py @@ -4,5 +4,5 @@ class PluginA(events.Plugin): configSection = "a" - def __init__(self): + def __init__(self) -> None: self.a = self.config.as_int("a", 0) diff --git a/nose2/tests/functional/support/scenario/test_class_fail/test_class_fail.py b/nose2/tests/functional/support/scenario/test_class_fail/test_class_fail.py index 95ec817a..4109eb43 100644 --- a/nose2/tests/functional/support/scenario/test_class_fail/test_class_fail.py +++ b/nose2/tests/functional/support/scenario/test_class_fail/test_class_fail.py @@ -1,5 +1,5 @@ class Test: - def __init__(self): + def __init__(self) -> None: raise RuntimeError( "Something bad happened but other tests should still be run!" ) diff --git a/nose2/tests/functional/test_discovery_loader.py b/nose2/tests/functional/test_discovery_loader.py index cc56abb5..87bf2844 100644 --- a/nose2/tests/functional/test_discovery_loader.py +++ b/nose2/tests/functional/test_discovery_loader.py @@ -4,7 +4,7 @@ class Watcher(events.Plugin): - def __init__(self): + def __init__(self) -> None: self.called = [] def loadTestsFromModule(self, event): diff --git a/nose2/tests/functional/test_util.py b/nose2/tests/functional/test_util.py index f412c59d..1f29d9eb 100644 --- a/nose2/tests/functional/test_util.py +++ b/nose2/tests/functional/test_util.py @@ -13,7 +13,7 @@ def test_name_from_path(self): def test_non_ascii_output(self): class D: - def __init__(self): + def __init__(self) -> None: self.out = [] def write(self, arg): diff --git a/nose2/tests/unit/test_buffer_plugin.py b/nose2/tests/unit/test_buffer_plugin.py index 21709ec0..a8d432e8 100644 --- a/nose2/tests/unit/test_buffer_plugin.py +++ b/nose2/tests/unit/test_buffer_plugin.py @@ -36,7 +36,7 @@ def test_mixed_unicode_and_nonascii_str(self): self.case = Test class Watcher(events.Plugin): - def __init__(self): + def __init__(self) -> None: self.events = [] def testOutcome(self, event): diff --git a/nose2/tests/unit/test_debugger_plugin.py b/nose2/tests/unit/test_debugger_plugin.py index 578956c1..c412d68e 100644 --- a/nose2/tests/unit/test_debugger_plugin.py +++ b/nose2/tests/unit/test_debugger_plugin.py @@ -11,7 +11,7 @@ def emit(self, record): class StubPdb: - def __init__(self): + def __init__(self) -> None: self.called = False self.tb = None diff --git a/nose2/tests/unit/test_loader.py b/nose2/tests/unit/test_loader.py index e1ed3665..b7af5921 100644 --- a/nose2/tests/unit/test_loader.py +++ b/nose2/tests/unit/test_loader.py @@ -76,7 +76,7 @@ def test_loader_from_names_calls_names_hook(self): class FakePlugin: - def __init__(self): + def __init__(self) -> None: self.fakeLoadFromModule = False self.fakeLoadFromName = False self.fakeLoadFromNames = False diff --git a/nose2/tests/unit/test_logcapture_plugin.py b/nose2/tests/unit/test_logcapture_plugin.py index 56346d18..8daea9d9 100644 --- a/nose2/tests/unit/test_logcapture_plugin.py +++ b/nose2/tests/unit/test_logcapture_plugin.py @@ -8,7 +8,7 @@ class StubLogging: - def __init__(self, name=None): + def __init__(self, name=None) -> None: self.name = name self.handlers = [] self.level = None @@ -29,7 +29,7 @@ def debug(self, message, *arg): class StubRecord: - def __init__(self, message): + def __init__(self, message) -> None: self.message = message self.name = "stub" self.levelname = "stub" diff --git a/nose2/tests/unit/test_outcomes_plugin.py b/nose2/tests/unit/test_outcomes_plugin.py index 21497773..d6bd6295 100644 --- a/nose2/tests/unit/test_outcomes_plugin.py +++ b/nose2/tests/unit/test_outcomes_plugin.py @@ -25,7 +25,7 @@ def test_e3(self): self.case = Test class Watcher(events.Plugin): - def __init__(self): + def __init__(self) -> None: self.outcomes = {} def testOutcome(self, event): diff --git a/nose2/tests/unit/test_printhooks_plugin.py b/nose2/tests/unit/test_printhooks_plugin.py index 5af053a8..130224c2 100644 --- a/nose2/tests/unit/test_printhooks_plugin.py +++ b/nose2/tests/unit/test_printhooks_plugin.py @@ -9,7 +9,7 @@ class CustomEvent(events.Event): _attrs = events.Event._attrs + ("args",) - def __init__(self, args, **kw): + def __init__(self, args, **kw) -> None: self.args = args super().__init__(**kw) diff --git a/nose2/tests/unit/test_testclass_loader.py b/nose2/tests/unit/test_testclass_loader.py index ae1b58d5..328672c3 100644 --- a/nose2/tests/unit/test_testclass_loader.py +++ b/nose2/tests/unit/test_testclass_loader.py @@ -88,7 +88,7 @@ class Mod: self.module = Mod() class TestA: - def __init__(self): + def __init__(self) -> None: raise RuntimeError("Something bad happened!") def test(self): diff --git a/nose2/tools/such.py b/nose2/tools/such.py index 0bbfffad..731a9e94 100644 --- a/nose2/tools/such.py +++ b/nose2/tools/such.py @@ -49,7 +49,7 @@ class Scenario: _helper = helper - def __init__(self, description): + def __init__(self, description) -> None: self._group = Group("A %s" % description, 0) @contextmanager @@ -340,7 +340,7 @@ def tearDown(cls): class Group: """A group of tests, with common fixtures and description""" - def __init__(self, description, indent=0, parent=None, base_layer=None): + def __init__(self, description, indent=0, parent=None, base_layer=None) -> None: self.description = description self.indent = indent self.parent = parent @@ -391,7 +391,7 @@ class Case: _helper = helper - def __init__(self, group, func, description): + def __init__(self, group, func, description) -> None: self.group = group self.func = func self.description = description diff --git a/nose2/util.py b/nose2/util.py index 88af2e6e..e29b2259 100644 --- a/nose2/util.py +++ b/nose2/util.py @@ -330,7 +330,7 @@ def _count_relevant_tb_levels(tb): class _WritelnDecorator: """Used to decorate file-like objects with a handy :func:`writeln` method""" - def __init__(self, stream): + def __init__(self, stream) -> None: self.stream = stream def __getattr__(self, attr): diff --git a/pyproject.toml b/pyproject.toml index a8be6d61..963b8fa1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries", From 30aaf86c4f750fbf15f615071532ac6322f8390c Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Sun, 15 Dec 2024 19:46:45 -0600 Subject: [PATCH 3/3] Fix mypy failures Due to slyp adding `-> None` annotations, some unannotated collection types are flagged. This does not add broader annotations, only the ones needed to get back to a healthy mypy state. Minor changes are included to generator function tests, but most parts of the library are unchanged. --- nose2/config.py | 4 ++- nose2/events.py | 31 ++++++++++++------- nose2/main.py | 11 ++++--- nose2/plugins/attrib.py | 7 +++-- nose2/plugins/layers.py | 4 ++- nose2/plugins/loader/generators.py | 23 +++++++++++--- nose2/plugins/mp.py | 9 ++++-- nose2/plugins/prettyassert.py | 5 ++- nose2/plugins/result.py | 4 ++- nose2/plugins/testid.py | 6 ++-- nose2/session.py | 6 ++-- nose2/sphinxext.py | 13 +++++--- nose2/tests/_common.py | 6 ++-- .../tests/functional/test_discovery_loader.py | 4 ++- nose2/tests/functional/test_util.py | 4 ++- nose2/tests/unit/test_buffer_plugin.py | 4 ++- nose2/tests/unit/test_logcapture_plugin.py | 4 ++- nose2/tests/unit/test_outcomes_plugin.py | 4 ++- nose2/tools/such.py | 21 +++++++------ 19 files changed, 114 insertions(+), 56 deletions(-) diff --git a/nose2/config.py b/nose2/config.py index 1b407e7e..1e8a0b4f 100644 --- a/nose2/config.py +++ b/nose2/config.py @@ -1,3 +1,5 @@ +from __future__ import annotations + TRUE_VALS = {"1", "t", "true", "on", "yes", "y"} __unittest = True @@ -13,7 +15,7 @@ class Config: def __init__(self, items) -> None: self._items = items - self._mvd = {} + self._mvd: dict[str, list[str]] = {} for k, v in items: self._mvd.setdefault(k, []).append(v) diff --git a/nose2/events.py b/nose2/events.py index 06969709..e2e1e9bf 100644 --- a/nose2/events.py +++ b/nose2/events.py @@ -12,6 +12,9 @@ from nose2 import config, util +if t.TYPE_CHECKING: + from nose2.session import Session + log = logging.getLogger(__name__) __unittest = True @@ -98,8 +101,12 @@ class Plugin(metaclass=PluginMeta): """ - alwaysOn = False - registered = False + # annotate instance vars created via PluginMeta + session: Session + config: config.Config + + alwaysOn: bool = False + registered: bool = False def register(self): """Register with appropriate hooks. @@ -226,7 +233,7 @@ class Hook: def __init__(self, method) -> None: self.method = method - self.plugins = [] + self.plugins: list[Plugin] = [] def __call__(self, event): for plugin in self.plugins[:]: @@ -320,7 +327,7 @@ class PluginInterface: hookClass: type[Hook] = Hook def __init__(self) -> None: - self.hooks = {} + self.hooks: dict[str, list[Hook]] = {} def addMethod(self, method): """Add a method to the available method. @@ -840,7 +847,7 @@ class LoadFromModuleEvent(Event): def __init__(self, loader, module, **kw) -> None: self.loader = loader self.module = module - self.extraTests = [] + self.extraTests: list[unittest.TestCase] = [] super().__init__(**kw) @@ -883,7 +890,7 @@ class LoadFromTestCaseEvent(Event): def __init__(self, loader, testCase, **kw) -> None: self.loader = loader self.testCase = testCase - self.extraTests = [] + self.extraTests: list[unittest.TestCase] = [] super().__init__(**kw) @@ -922,7 +929,7 @@ def __init__(self, loader, names, module, **kw) -> None: self.loader = loader self.names = names self.module = module - self.extraTests = [] + self.extraTests: list[unittest.TestCase] = [] super().__init__(**kw) def __str__(self): @@ -964,7 +971,7 @@ def __init__(self, loader, name, module, **kw) -> None: self.loader = loader self.name = name self.module = module - self.extraTests = [] + self.extraTests: list[unittest.TestCase] = [] super().__init__(**kw) @@ -1013,7 +1020,7 @@ class HandleFileEvent(Event): _attrs = Event._attrs + ("loader", "name", "path", "pattern", "topLevelDirectory") def __init__(self, loader, name, path, pattern, topLevelDirectory, **kw) -> None: - self.extraTests = [] + self.extraTests: list[unittest.TestCase] = [] self.path = path self.loader = loader self.name = name @@ -1105,8 +1112,8 @@ def __init__(self, loader, testCase, isTestMethod, **kw) -> None: self.loader = loader self.testCase = testCase self.testMethodPrefix = None - self.extraNames = [] - self.excludedNames = [] + self.extraNames: list[str] = [] + self.excludedNames: list[str] = [] self.isTestMethod = isTestMethod super().__init__(**kw) @@ -1212,7 +1219,7 @@ class OutcomeDetailEvent(Event): def __init__(self, outcomeEvent, **kw) -> None: self.outcomeEvent = outcomeEvent - self.extraDetail = [] + self.extraDetail: list[str] = [] super().__init__(**kw) diff --git a/nose2/main.py b/nose2/main.py index dbb834fa..8f711b3e 100644 --- a/nose2/main.py +++ b/nose2/main.py @@ -1,6 +1,9 @@ +from __future__ import annotations + import logging import os import sys +import typing as t import unittest from nose2 import events, loader, plugins, runner, session, util @@ -71,16 +74,16 @@ class PluggableTestProgram(unittest.TestProgram): _currentSession = None loaderClass = loader.PluggableTestLoader runnerClass = runner.PluggableTestRunner - defaultPlugins = plugins.DEFAULT_PLUGINS - excludePlugins = () + defaultPlugins: t.ClassVar[t.Sequence[str]] = plugins.DEFAULT_PLUGINS + excludePlugins: t.ClassVar[t.Sequence[str]] = () # XXX override __init__ to warn that testLoader and testRunner are ignored? def __init__(self, **kw) -> None: plugins = kw.pop("plugins", []) exclude = kw.pop("excludePlugins", []) hooks = kw.pop("extraHooks", []) - self.defaultPlugins = list(self.defaultPlugins) - self.excludePlugins = list(self.excludePlugins) + self.defaultPlugins: list[str] = list(self.defaultPlugins) # type: ignore[misc] + self.excludePlugins: list[str] = list(self.excludePlugins) # type: ignore[misc] self.extraHooks = hooks self.defaultPlugins.extend(plugins) self.excludePlugins.extend(exclude) diff --git a/nose2/plugins/attrib.py b/nose2/plugins/attrib.py index caca3125..99264ec8 100644 --- a/nose2/plugins/attrib.py +++ b/nose2/plugins/attrib.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import logging +import typing as t from unittest import TestSuite from nose2.events import Plugin @@ -11,8 +14,8 @@ class AttributeSelector(Plugin): """Filter tests by attribute""" def __init__(self) -> None: - self.attribs = [] - self.eval_attribs = [] + self.attribs: list[tuple[str, t.Callable[..., t.Any]]] = [] + self.eval_attribs: list[str] = [] self.addArgument( self.attribs, "A", "attribute", "Select tests with matching attribute" ) diff --git a/nose2/plugins/layers.py b/nose2/plugins/layers.py index 4166bc99..ca9105c2 100644 --- a/nose2/plugins/layers.py +++ b/nose2/plugins/layers.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging import re from collections import OrderedDict @@ -205,7 +207,7 @@ def __init__(self) -> None: "highlight-words", ["A", "having", "should"] ) self.highlight_re = re.compile(r"\b(%s)\b" % "|".join(self.highlight_words)) - self.layersReported = set() + self.layersReported: set[LayerSuite] = set() def reportStartTest(self, event): if self.session.verbosity < 2: diff --git a/nose2/plugins/loader/generators.py b/nose2/plugins/loader/generators.py index c38c69f2..34c93704 100644 --- a/nose2/plugins/loader/generators.py +++ b/nose2/plugins/loader/generators.py @@ -30,6 +30,7 @@ def test_gen(): import logging import sys import types +import typing as t import unittest from nose2 import exceptions, util @@ -228,13 +229,19 @@ def createTest(name): class GeneratorFunctionCase(unittest.FunctionTestCase): - def __init__(self, name, **args) -> None: + def __init__(self, name: str, **args: t.Any) -> None: self._funcName = name - unittest.FunctionTestCase.__init__(self, None, **args) + # initialize with a placeholder, but it won't be used + # it gets overwritten with `_testFunc` below + unittest.FunctionTestCase.__init__(self, _placeholder_func, **args) - _testFunc = property( - lambda self: getattr(self, self._funcName), lambda self, func: None - ) + @property + def _testFunc(self) -> t.Callable[..., t.Any]: + return getattr(self, self._funcName) + + @_testFunc.setter + def _testFunc(self, newfunc: t.Callable[..., t.Any]) -> None: + pass def __repr__(self): return self._funcName @@ -242,6 +249,12 @@ def __repr__(self): id = __str__ = __repr__ +def _placeholder_func() -> None: + """ + A no-op defined for use inside of GeneratorFunctionCase init. + """ + + def GeneratorMethodCase(cls): class _GeneratorMethodCase(GeneratorFunctionCase): if util.has_class_fixtures(cls): diff --git a/nose2/plugins/mp.py b/nose2/plugins/mp.py index 0d02a40b..7d3fad14 100644 --- a/nose2/plugins/mp.py +++ b/nose2/plugins/mp.py @@ -1,9 +1,12 @@ +from __future__ import annotations + import logging import multiprocessing import multiprocessing.connection as connection import os import select import sys +import typing as t import unittest from collections.abc import Sequence @@ -26,7 +29,7 @@ def __init__(self) -> None: self._procs = self.config.as_int("processes", 0) self.setAddress(self.config.as_str("bind_address", None)) - self.cases = {} + self.cases: dict[str, unittest.TestCase] = {} @property def procs(self): @@ -458,7 +461,7 @@ def registerInSubprocess(self, event): """ def __init__(self, **metadata) -> None: - self.pluginClasses = [] + self.pluginClasses: list[type[events.Plugin]] = [] super().__init__(**metadata) @@ -487,7 +490,7 @@ class RecordingPluginInterface(events.PluginInterface): def __init__(self) -> None: super().__init__() - self.events = [] + self.events: list[tuple[t.Callable[..., t.Any], events.Event]] = [] def log(self, method, event): self.events.append((method, event)) diff --git a/nose2/plugins/prettyassert.py b/nose2/plugins/prettyassert.py index 573e208c..3d82bbac 100644 --- a/nose2/plugins/prettyassert.py +++ b/nose2/plugins/prettyassert.py @@ -10,12 +10,15 @@ """ +from __future__ import annotations + import collections import inspect import io import re import textwrap import tokenize +import typing as t from nose2 import events @@ -262,7 +265,7 @@ def __init__(self, frame_locals, frame_globals) -> None: # they were encountered # track which tokens we've seen to avoid duplicates if a name appears # twice, as in `assert x != x` - self.seen_tokens = collections.OrderedDict() + self.seen_tokens: dict[str, t.Any] = {} # the previous token seen as a tuple of (tok_type, token_name) # (or None when we start) diff --git a/nose2/plugins/result.py b/nose2/plugins/result.py index cab62d73..34484db3 100644 --- a/nose2/plugins/result.py +++ b/nose2/plugins/result.py @@ -26,6 +26,8 @@ # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html +from __future__ import annotations + import sys import unittest @@ -44,7 +46,7 @@ class ResultReporter(events.Plugin): def __init__(self) -> None: self.testsRun = 0 - self.reportCategories = { + self.reportCategories: dict[str, list[events.Event]] = { "failures": [], "errors": [], "skipped": [], diff --git a/nose2/plugins/testid.py b/nose2/plugins/testid.py index 2655b3c8..512c3bfd 100644 --- a/nose2/plugins/testid.py +++ b/nose2/plugins/testid.py @@ -11,6 +11,8 @@ """ +from __future__ import annotations + import os import pickle import re @@ -30,8 +32,8 @@ class TestId(Plugin): def __init__(self) -> None: self.idfile = self.config.as_str("id-file", ".noseids") - self.ids = {} - self.tests = {} + self.ids: dict[str, str] = {} + self.tests: dict[str, str] = {} if not os.path.isabs(self.idfile): # FIXME expand-user? self.idfile = os.path.join(os.getcwd(), self.idfile) diff --git a/nose2/session.py b/nose2/session.py index 408b5c61..a477a2c9 100644 --- a/nose2/session.py +++ b/nose2/session.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import argparse import logging import os @@ -80,7 +82,7 @@ def __init__(self) -> None: ) self.config = ConfigParser() self.hooks = events.PluginInterface() - self.plugins = [] + self.plugins: list[events.Plugin] = [] # this will be reset later, whenever handleCfgArgs happens, but it # starts at 1 so that it always has a non-negative integer value self.verbosity = 1 @@ -89,7 +91,7 @@ def __init__(self) -> None: self.testResult = None self.testLoader = None self.logLevel = logging.WARN - self.configCache = {} + self.configCache: dict[str, dict[str, config.Config]] = {} def get(self, section): """Get a config section. diff --git a/nose2/sphinxext.py b/nose2/sphinxext.py index 26c83510..066325c1 100644 --- a/nose2/sphinxext.py +++ b/nose2/sphinxext.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import types +import typing as t from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -174,7 +177,7 @@ def setup(app): class ConfigBucket: def __init__(self) -> None: self.section = None - self.vars = {} + self.vars: dict[str, dict[str, t.Any]] = {} def __call__(self, items): self.vars = dict(items) @@ -219,10 +222,10 @@ def get(self, item, default=DEFAULT): class OptBucket: def __init__(self, doc=None, prog="nosetests") -> None: - self.seen = set() - self.opts = [] - self.doc = doc - self.prog = prog + self.seen: set[t.Any] = set() + self.opts: list[Opt] = [] + self.doc: str | None = doc + self.prog: str = prog def __iter__(self): return iter(self.opts) diff --git a/nose2/tests/_common.py b/nose2/tests/_common.py index 5cd40d7c..93b0a766 100644 --- a/nose2/tests/_common.py +++ b/nose2/tests/_common.py @@ -107,7 +107,7 @@ class _FakeEventBase: def __init__(self) -> None: self.handled = False self.version = "0.1" - self.metadata = {} + self.metadata: dict = {} class FakeHandleFileEvent(_FakeEventBase): @@ -119,7 +119,7 @@ def __init__(self, name) -> None: self.loader = Stub() # FIXME self.name = name self.path = os.path.split(name)[1] - self.extraTests = [] + self.extraTests: list = [] class FakeStartTestEvent(_FakeEventBase): @@ -271,7 +271,7 @@ def __exit__(self, exc_type, exc_value, traceback): class Conn: def __init__(self, items) -> None: self.items = items - self.sent = [] + self.sent: list = [] self.closed = False def recv(self): diff --git a/nose2/tests/functional/test_discovery_loader.py b/nose2/tests/functional/test_discovery_loader.py index 87bf2844..8a6e4fb7 100644 --- a/nose2/tests/functional/test_discovery_loader.py +++ b/nose2/tests/functional/test_discovery_loader.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from nose2 import events, loader, session from nose2.plugins.loader.discovery import DiscoveryLoader from nose2.tests._common import FunctionalTestCase, TestCase, support_file @@ -5,7 +7,7 @@ class Watcher(events.Plugin): def __init__(self) -> None: - self.called = [] + self.called: list[events.LoadFromModuleEvent] = [] def loadTestsFromModule(self, event): self.called.append(event) diff --git a/nose2/tests/functional/test_util.py b/nose2/tests/functional/test_util.py index 1f29d9eb..aa9a04c6 100644 --- a/nose2/tests/functional/test_util.py +++ b/nose2/tests/functional/test_util.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from nose2 import util from nose2.tests._common import TestCase, support_file @@ -14,7 +16,7 @@ def test_name_from_path(self): def test_non_ascii_output(self): class D: def __init__(self) -> None: - self.out = [] + self.out: list[str] = [] def write(self, arg): self.out.append(arg) diff --git a/nose2/tests/unit/test_buffer_plugin.py b/nose2/tests/unit/test_buffer_plugin.py index a8d432e8..f5f7dc12 100644 --- a/nose2/tests/unit/test_buffer_plugin.py +++ b/nose2/tests/unit/test_buffer_plugin.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import io import sys @@ -37,7 +39,7 @@ def test_mixed_unicode_and_nonascii_str(self): class Watcher(events.Plugin): def __init__(self) -> None: - self.events = [] + self.events: list[events.TestOutcomeEvent] = [] def testOutcome(self, event): self.events.append(event) diff --git a/nose2/tests/unit/test_logcapture_plugin.py b/nose2/tests/unit/test_logcapture_plugin.py index 8daea9d9..4e29a4c6 100644 --- a/nose2/tests/unit/test_logcapture_plugin.py +++ b/nose2/tests/unit/test_logcapture_plugin.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging from nose2 import session @@ -10,7 +12,7 @@ class StubLogging: def __init__(self, name=None) -> None: self.name = name - self.handlers = [] + self.handlers: list[logging.Handler] = [] self.level = None def getLogger(self, _name=None): diff --git a/nose2/tests/unit/test_outcomes_plugin.py b/nose2/tests/unit/test_outcomes_plugin.py index d6bd6295..41f19643 100644 --- a/nose2/tests/unit/test_outcomes_plugin.py +++ b/nose2/tests/unit/test_outcomes_plugin.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from nose2 import events, result, session from nose2.plugins import outcomes from nose2.tests._common import TestCase @@ -26,7 +28,7 @@ def test_e3(self): class Watcher(events.Plugin): def __init__(self) -> None: - self.outcomes = {} + self.outcomes: dict[str, list[events.TestOutcomeEvent]] = {} def testOutcome(self, event): self.outcomes.setdefault(event.outcome, []).append(event) diff --git a/nose2/tools/such.py b/nose2/tools/such.py index 731a9e94..39a5d577 100644 --- a/nose2/tools/such.py +++ b/nose2/tools/such.py @@ -1,5 +1,8 @@ +from __future__ import annotations + import logging import sys +import typing as t import unittest from contextlib import contextmanager @@ -345,13 +348,13 @@ def __init__(self, description, indent=0, parent=None, base_layer=None) -> None: self.indent = indent self.parent = parent self.base_layer = base_layer - self.mixins = [] - self._cases = [] - self._setups = [] - self._teardowns = [] - self._test_setups = [] - self._test_teardowns = [] - self._children = [] + self.mixins: list[type] = [] + self._cases: list[unittest.TestCase] = [] + self._setups: list[t.Callable[..., t.Any]] = [] + self._teardowns: list[t.Callable[..., t.Any]] = [] + self._test_setups: list[t.Callable[..., t.Any]] = [] + self._test_teardowns: list[t.Callable[..., t.Any]] = [] + self._children: list[Group] = [] def addCase(self, case): if not self._cases: @@ -395,8 +398,8 @@ def __init__(self, group, func, description) -> None: self.group = group self.func = func self.description = description - self._setups = [] - self._teardowns = [] + self._setups: list[t.Callable[..., t.Any]] = [] + self._teardowns: list[t.Callable[..., t.Any]] = [] self.first = False self.full = False