approvals / approvals/ApprovalTests.Python

Generic type hints for `verify_all`'s `alist` and `formatter` parameters

Open
#176 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
212
Forks
56
Avg merge
1m
Merged PRs (30d)
1

Description

The verify_all function currently hints the parameters a_list as List[str] and formatter as Optional[Callable]. Perhaps better type hints would be (using 3.12 syntax but this could be done with the old-style generic type syntax):

def verify_all[T](
    ...
    alist: List[T],
    formatter: Optional[Callable[[T], str]] = None,
    ...
) -> None:

This would allow for any object to be passed in as the expected result with the formatter transforming the object into a string for approval — without type checkers complaining.

In fact, the default formatter for this function already calls str by default on objects from alist (see list_utils.py) when transforming the list to a string.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the verify_all entry point and inspect list_utils.py, especially the default formatter referenced in the issue. Update the annotations so alist accepts a generic element type and formatter accepts that type and returns a string; done means the annotations support object values without type-checker complaints.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.