syrupy-project / syrupy

:pancakes: The sweeter pytest snapshot plugin
https://syrupy-project.github.io/syrupy/
Apache License 2.0
553 stars 36 forks source link

chore: use tuple in stdout.re_match_lines #919

Closed epenet closed 2 weeks ago

epenet commented 2 weeks ago

Description

This was spotted when trying to enforce pyupgrade rules in ruff, and rule UP034 was causing issues: https://docs.astral.sh/ruff/rules/extraneous-parentheses/

Sometimes the first argument was a tuple stdout.re_match_lines(("a","b")), sometimes it was a raw string stdout.re_match_lines("a"), and other times it was a bracketed raw string stdout.re_match_lines(("a"))

Instead of simply converting the bracketed raw string into non-bracketed raw strings, I think it makes better sense to convert all the raw strings to tuples, as result.stdout.re_match_lines is supposed to have a Sequence[str] as first argument:

    def re_match_lines(
        self, lines2: Sequence[str], *, consecutive: bool = False
    ) -> None:

Related Issues

Checklist

Additional Comments

This is not picked up by mypy as strings are also a sequence of single-character strings. Also, raw strings work behind the scene as they go through _getlines which converts them to a sequence.

    def _getlines(self, lines2: str | Sequence[str] | Source) -> Sequence[str]:
        if isinstance(lines2, str):
            lines2 = Source(lines2)
        if isinstance(lines2, Source):
            lines2 = lines2.strip().lines
        return lines2
codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #919   +/-   ##
=======================================
  Coverage   97.74%   97.74%           
=======================================
  Files          21       21           
  Lines        1596     1596           
=======================================
  Hits         1560     1560           
  Misses         36       36           

🚨 Try these New Features:

noahnu commented 4 days ago

:tada: This PR is included in version 4.8.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: