Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use tuple in stdout.re_match_lines #919

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

epenet
Copy link
Contributor

@epenet epenet commented Nov 12, 2024

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

  • This PR has sufficient documentation.
  • This PR has sufficient test coverage.
  • This PR title satisfies semantic convention.

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

@epenet epenet changed the title chore: remove extraneous parentheses in tests chore: fix UP034 extraneous-parentheses in tests Nov 12, 2024
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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:

@epenet epenet changed the title chore: fix UP034 extraneous-parentheses in tests chore: use tuple in stdout.re_match_lines Nov 12, 2024
@epenet epenet mentioned this pull request Nov 12, 2024
6 tasks
@noahnu noahnu merged commit 46d2e4d into syrupy-project:main Nov 13, 2024
15 of 17 checks passed
@epenet epenet deleted the 20241112-0748 branch November 13, 2024 22:15
@noahnu
Copy link
Collaborator

noahnu commented Nov 23, 2024

🎉 This PR is included in version 4.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants