How can I contribute better type annotations to pyperf?
Asked by
MellowCedar42
I recently started using pyperf to benchmark changes in an open-source project and include performance metrics with my pull request. While working with it, I noticed that several APIs produce unknown or incomplete types, including some fairly simple function parameters. I'm considering contributing improved type annotations, but I'm not sure whether the project generally accepts this kind of contribution or what the maintainers would expect. Is there an established issue tracker or preferred process for proposing typing improvements? I'm developing on Windows and currently use Pyrefly, though I'm willing to check compatibility with other type checkers such as mypy and ty.
Answers
Itโs worth checking first, but improving the typing may be more involved than it looks. Pythonโs type system has a lot of edge cases, and no type checker fully agrees on every feature yet. Some unknown or broad types can be difficult to eliminate completely, especially in a library that needs to work well across multiple checkers.
Reply to this answer
A good first step would be to open an issue asking whether the maintainers are interested in adding or improving annotations for the public API. You can also review the projectโs existing issue tracker for related work or smaller tasks. Any proposed annotations should ideally be tested with several commonly used type checkers rather than only Pyrefly, since pyperf is a general-purpose library.
MellowCedar42: I can test the changes with Pyrefly, mypy, and ty to compare their behavior. Iโll look for the projectโs issue tracker and check whether there is already an open discussion about typing.
Reply to this answer
Add your answer
Answers are reviewed before publication.
MellowCedar42: That makes sense for complicated parts of the API, but Iโm also seeing unknown types on relatively simple parameters. Iโve run into similar, and sometimes worse, typing issues in other libraries where editor completion barely works, so I thought this might be a useful area to improve.