{"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/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/pytester.py#L1685-L1721","documentation":"Raised by RunResult._match_lines (the engine behind fnmatch_lines and re_match_lines) when the lines2 argument is not a collections.abc.Sequence. The matching algorithm requires an ordered, indexable sequence of patterns; a generator, set, or single string-in-a-non-sequence is rejected before matching begins.","triggerScenarios":"Passing a generator expression, set, dict, or other non-Sequence iterable to result.fnmatch_lines(...) or result.re_match_lines(...); passing a bare non-iterable.","commonSituations":"Writing fnmatch_lines(x for x in patterns) with a generator instead of a list; passing a set of patterns whose ordering would be nondeterministic; refactoring from a list to another iterable type.","solutions":["Wrap the iterable in list() before passing: fnmatch_lines(list(patterns)).","Use a list or tuple literal directly.","Avoid generators/sets for line-matching arguments since order matters for consecutive matching."],"exampleFix":"// before\nresult.fnmatch_lines(p for p in patterns)  # generator\n// after\nresult.fnmatch_lines(list(patterns))","handlingStrategy":"type-guard","validationCode":"from collections.abc import Sequence\n\nif not isinstance(patterns, Sequence):\n    patterns = list(patterns)\nresult.fnmatch_lines(patterns)","typeGuard":"from collections.abc import Sequence\nfrom typing import Any\n\ndef is_sequence_of_str(v: Any) -> bool:\n    return isinstance(v, Sequence) and all(isinstance(x, str) for x in v)","tryCatchPattern":null,"preventionTips":["Always pass a list or tuple to fnmatch_lines/re_match_lines.","Avoid generators since order matters for consecutive matching.","Wrap iterables with list() if their type is uncertain."],"tags":["pytester","type-validation","assertion"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}