{"record":{"id":"5ab1b6753d717bd8","repo":"pytest-dev/pytest","slug":"invalid-type-for-lines2-type-lines2-name","errorCode":null,"errorMessage":"invalid type for lines2: {type(lines2).__name__}","messagePattern":"invalid type for lines2: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/pytester.py","lineNumber":1703,"sourceCode":"        consecutive: bool = False,\n    ) -> None:\n        \"\"\"Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``.\n\n        :param Sequence[str] lines2:\n            List of string patterns to match. The actual format depends on\n            ``match_func``.\n        :param match_func:\n            A callable ``match_func(line, pattern)`` where line is the\n            captured line from stdout/stderr and pattern is the matching\n            pattern.\n        :param str match_nickname:\n            The nickname for the match function that will be logged to stdout\n            when a match occurs.\n        :param consecutive:\n            Match lines consecutively?\n        \"\"\"\n        if not isinstance(lines2, collections.abc.Sequence):\n            raise TypeError(f\"invalid type for lines2: {type(lines2).__name__}\")\n        lines2 = self._getlines(lines2)\n        lines1 = self.lines[:]\n        extralines = []\n        __tracebackhide__ = True\n        wnick = len(match_nickname) + 1\n        started = False\n        for line in lines2:\n            nomatchprinted = False\n            while lines1:\n                nextline = lines1.pop(0)\n                if line == nextline:\n                    self._log(\"exact match:\", repr(line))\n                    started = True\n                    break\n                elif match_func(nextline, line):\n                    self._log(f\"{match_nickname}:\", repr(line))\n                    self._log(\n                        \"{:>{width}}\".format(\"with:\", width=wnick), repr(nextline)","sourceCodeStart":1685,"sourceCodeEnd":1721,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/pytester.py#L1685-L1721","documentation":"Thrown by LineMatcher._match_lines() when the lines2 argument is not a collections.abc.Sequence (e.g. a generator, set, or mapping). fnmatch_lines/re_match_lines require indexable, re-iterable sequence input.","triggerScenarios":"Passing a generator expression to fnmatch_lines: result.stdout.fnmatch_lines(l.upper() for l in lines); passing a set or dict; passing an iterator object.","commonSituations":"Using a generator comprehension for brevity; passing a set of expected lines; transforming lines with map() which returns an iterator in Python 3.","solutions":["Wrap the iterable in list(): fnmatch_lines(list(...)).","Pass a list or tuple literal directly.","Materialize generators before the call."],"exampleFix":"// before\nresult.stdout.fnmatch_lines(l.upper() for l in expected)\n// after\nresult.stdout.fnmatch_lines([l.upper() for l in expected])","handlingStrategy":"type-guard","validationCode":"if not isinstance(lines2, collections.abc.Sequence):\n    lines2 = list(lines2)\nresult.stdout.fnmatch_lines(lines2)","typeGuard":"import collections.abc\ndef is_sequence_for_match(lines2: object) -> bool:\n    return isinstance(lines2, collections.abc.Sequence)","tryCatchPattern":null,"preventionTips":["Pass lists or tuples to fnmatch_lines/re_match_lines.","Materialize generators/iterators before the call.","Avoid sets/dicts which are not Sequences."],"tags":["pytester","linematcher","type-error","sequence"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}