Skip to content

ci: add matchify pre-commit hook - #15356

Open
kadubhumika wants to merge 6 commits into
TheAlgorithms:masterfrom
kadubhumika:add-matchify-precommit
Open

kadubhumika wants to merge 6 commits into
TheAlgorithms:masterfrom
kadubhumika:add-matchify-precommit

Conversation

@kadubhumika

Copy link
Copy Markdown
Contributor

Summary

  • Add Matchify as a pre-commit hook.
  • Exclude data_structures/linked_list/doubly_linked_list.py because its
    conversion produces a less readable case self.head pattern.

Testing

  • pre-commit validate-config passed.
  • pre-commit run --all-files was run.
  • Matchify executed successfully and converted applicable files.
  • Confirmed doubly_linked_list.py remains excluded from Matchify.
  • Restored unrelated changes produced by the full pre-commit run.

Fixes #15337

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed merge conflicts Open a new PR or rebase on the latest commit enhancement This PR modified some existing files labels Sep 16, 2026
@algorithms-keeper algorithms-keeper Bot removed the merge conflicts Open a new PR or rebase on the latest commit label Sep 16, 2026
@kadubhumika

Copy link
Copy Markdown
Contributor Author

Hi @cclauss @priya-sundaram-dev ,

The merge conflicts have been resolved and all required checks are now passing.
The PR adds Matchify as a pre-commit hook, with doubly_linked_list.py excluded because the resulting pattern is less readable.
Would appreciate a review when you have time. Thank you!

@priya-sundaram-dev priya-sundaram-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for resolving the conflicts, @kadubhumika! One thing to flag before this can go in, though — right now the PR has no net change. Comparing the branch against master:

$ git diff master...add-matchify-precommit --stat
(0 files changed)

GitHub agrees: the PR shows 0 changed files. It looks like the last merge commit (6b907e5 Merge branch 'master') resolved the conflict in .pre-commit-config.yaml by taking master's side, which discarded the matchify hook that commit 6d6eee5 had added. matchify no longer appears anywhere in the branch's .pre-commit-config.yaml, so as it stands merging this wouldn't add the hook.

To fix: re-apply the matchify block on top of the current merged state, e.g.

  - repo: https://github.com/15r10nk/matchify
    rev: <pinned-version>
    hooks:
      - id: matchify
        exclude: ^data_structures/linked_list/doubly_linked_list\.py$

(keeping the doubly_linked_list.py exclusion you mentioned, since the rewritten pattern is less readable there). Once git diff master... shows the hook being added again and CI is green, happy to re-review. 🙂

@kadubhumika
kadubhumika force-pushed the add-matchify-precommit branch from 6b907e5 to dae13f1 Compare September 16, 2026 09:16
@algorithms-keeper algorithms-keeper Bot added the tests are failing Do not merge until tests pass label Sep 16, 2026
Comment thread .pre-commit-config.yaml
rev: "0.26"
hooks:
- id: validate-pyproject
- repo: https://github.com/15r10nk/matchify

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the file leaves a blank line between hooks for readability.

Suggested change
- repo: https://github.com/15r10nk/matchify
- repo: https://github.com/15r10nk/matchify

@cclauss

cclauss commented Sep 16, 2026

Copy link
Copy Markdown
Member

Please run:
% ruff format

@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Confirmed — the hook is now genuinely applied: .pre-commit-config.yaml adds the matchify repo (rev v0.2.0) with the doubly_linked_list.py exclusion, and git diff master... now shows the 42-file reformat rather than the empty diff from before. Nice, that clears the blocker I flagged.

One thing to watch on @cclauss's ruff format note: matchify and ruff can disagree on line-wrapping after a rewrite, so run them in the order the CI does (matchify → ruff format → ruff check) and commit the result, otherwise pre-commit may keep re-modifying files. Once CI is green this looks good to me.

@kadubhumika

Copy link
Copy Markdown
Contributor Author

@cclauss @priya-sundaram-dev Thanks for the feedback! I’ve run ruff format locally and confirmed that all files are already formatted. I’ll also add the requested blank line before the Matchify hook for consistency with the rest of the configuration.

Comment thread matrix/matrix_class.py Outdated
@algorithms-keeper algorithms-keeper Bot removed tests are failing Do not merge until tests pass labels Sep 16, 2026
@cclauss

cclauss commented Sep 16, 2026

Copy link
Copy Markdown
Member

@priya-sundaram-dev In #15337 (comment) you flagged the matchify change in one file.

Do you flag any matchify changes in this pull request? Are the files more or less verbose with these changes?

@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Good question — I went through the whole diff for this PR, not just spot-checks.

Do I flag any conversion here? No. The thing I flagged in #15337 was one specific construct: a dotted value-pattern (if current == self.headcase self.head:), which is correct but reads like a capture and trips people up. That construct doesn't appear anywhere in this PR — and the file it was in, doubly_linked_list.py, is the one explicitly excluded by the hook. I scanned all ~137 added case arms and they're the unambiguous kinds:

  • literals — case 1:, case "encrypt":, case "sjf (preemptive)":
  • singletons — case None:, case False:
  • class patterns, some guarded — case Vector():, case Matrix():, case int() | float():, case set() if isinstance(set_b, set):

None of those can be misread as a capture, so I'd be happy to see them land.

More or less verbose? Marginally more by line count, not by complexity. There are ~48 if/elif chains converted to match, for a net of roughly +70 lines across the 42 files — about +1.5 lines per conversion. That's essentially the one match subject: header line plus one extra indent level each; the branch bodies are unchanged. So the code isn't doing more, it's the same dispatch nested one level deeper. Where the subject is a single value dispatched to several literals (the cipher main() menus, the scheduling algorithm selector), I think the match reads clearer and earns that extra line. Nowhere in this PR did the rewrite cost readability the way the self.head case did.

@cclauss

cclauss commented Sep 16, 2026

Copy link
Copy Markdown
Member

Awesome teamwork. I approve this, but I am going to hold off on merging it until just before Hacktoberfest 2026 starts.

If not, it will cause many of our 375 pull requests to fail in CI. Once we have far fewer PRs, we will rerun and test this, and then merge it. Really awesome work!! Thanks much.

@cclauss cclauss added on hold and removed awaiting reviews This PR is ready to be reviewed labels Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files on hold

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should we add matchify to pre-commit

3 participants