Repository: pytest-dev/pytest
File: src/_pytest/_code/code.py (Python)

Code before:
        elif style == "value":
            if excinfo:
                lines.extend(str(excinfo.value).split("\n"))
            return ReprEntry(lines, None, None, None, style)
        else:
            if excinfo:
                lines.extend(self.get_exconly(excinfo, indent=4))
            return ReprEntry(lines, None, None, None, style)

    def _makepath(self, path: Path | str) -> str:
        if not self.abspath and isinstance(path, Path):
            try:
                np = bestrelpath(Path.cwd(), path)
            except OSError:
                return str(path)
            if len(np) < len(str(path)):
                return np
        return str(path)

    def _filtered_traceback(self, excinfo: ExceptionInfo[BaseException]) -> Traceback:
        traceback_ = excinfo.traceback
        if callable(self.tbfilter):
            traceback_ = self.tbfilter(excinfo)
        elif self.tbfilter:
            traceback_ = traceback_.filter(excinfo)
        return traceback_

    def repr_traceback(self, excinfo: ExceptionInfo[BaseException]) -> ReprTraceback:
        traceback_ = self._filtered_traceback(excinfo)

        if isinstance(excinfo.value, RecursionError):
            traceback_, extraline = self._truncate_recursive_traceback(traceback_)
        else:
            extraline = None

        if not traceback_:
            if extraline is None:
                extraline = "All traceback entries are hidden. Pass `--full-trace` to see hidden and internal frames."
            entries = [self.repr_traceback_entry(None, excinfo)]
            return ReprTraceback(entries, extraline, style=self.style)

        last = traceback_[-1]
        if self.style == "value":
            entries = [self.repr_traceback_entry(last, excinfo)]
            return ReprTraceback(entries, None, style=self.style)

        entries = [
            self.repr_traceback_entry(entry, excinfo if last == entry else None)
            for entry in traceback_
        ]
        return ReprTraceback(entries, extraline, style=self.style)

Review comment (refactor):
not much reason to have a variable in the helper function at all tbh:
```python
if callable(self.tbfilter):
    return self.tbfilter(excinfo)
elif self.tbfilter:
    return excinfo.traceback.filter(excinfo)
return excinfo.traceback
```

Code after:
                colno=colno,
                end_colno=end_colno,
            )
            lines.extend(s)
            if short:
                message = f"in {entry.name}"
            else:
                message = (excinfo and excinfo.typename) or ""
            entry_path = entry.path
            path = self._makepath(entry_path)
            reprfileloc = ReprFileLocation(path, entry.lineno + 1, message)
            localsrepr = self.repr_locals(entry.locals)
            return ReprEntry(lines, reprargs, localsrepr, reprfileloc, style)
        elif style == "value":
            if excinfo:
                lines.extend(str(excinfo.value).split("\n"))
            return ReprEntry(lines, None, None, None, style)
        else:
            if excinfo:
                lines.extend(self.get_exconly(excinfo, indent=4))
            return ReprEntry(lines, None, None, None, style)

    def _makepath(self, path: Path | str) -> str:
        if not self.abspath and isinstance(path, Path):
            try:
                np = bestrelpath(Path.cwd(), path)
            except OSError:
                return str(path)
            if len(np) < len(str(path)):
                return np
        return str(path)

    def repr_traceback(self, excinfo: ExceptionInfo[BaseException]) -> ReprTraceback:
        traceback = filter_excinfo_traceback(self.tbfilter, excinfo)

        if isinstance(excinfo.value, RecursionError):
            traceback, extraline = self._truncate_recursive_traceback(traceback)
        else:
            extraline = None

        if not traceback:
            if extraline is None:
                extraline = "All traceback entries are hidden. Pass `--full-trace` to see hidden and internal frames."
            entries = [self.repr_traceback_entry(None, excinfo)]
            return ReprTraceback(entries, extraline, style=self.style)

        last = traceback[-1]
        if self.style == "value":
            entries = [self.repr_traceback_entry(last, excinfo)]
            return ReprTraceback(entries, None, style=self.style)