Skip to content

Improving type system for pyperf library - #257

Draft
DebanKsahu wants to merge 4 commits into
psf:mainfrom
DebanKsahu:impr/type_system
Draft

DebanKsahu wants to merge 4 commits into
psf:mainfrom
DebanKsahu:impr/type_system

Conversation

@DebanKsahu

@DebanKsahu DebanKsahu commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Description

_utils.py

  • In tdist95conf_level function the doc string clearly mention that df means degree of freedom and expected to be a int that's why I type annotated it with int. Now that tdist95conf_level showing that it required a int degree of freedom so there no need for df = int(round(df))` as it's now user's reponsibility to pass correct value.
  • pooled_sample_variance, tscore and is_significant all required input of type Sequence[float] because the inputs are iterated over many time so we can't accept an Iterable[float] because it will exhaust the base list.

Fixes #255

@vstinner

vstinner commented Sep 7, 2026

Copy link
Copy Markdown
Member

I understood that having wrong type annotations can be worse than not having type annotations. We should check if type annotations are correct using a tool (such as mypy) to make sure that they remain correct when the code will evolve. What is your plan to check type annotations?

Does this PR add all type annotations? Or do you plan further changes?

@DebanKsahu

Copy link
Copy Markdown
Contributor Author

I am planning to add all type annotations in this PR only. For the testing part I am planning to use pyrefly, we can add the settings to pyproject.toml file only and add this test into the commit hook just like ruff.

@vstinner

Copy link
Copy Markdown
Member

Would it be possible to include the type check integration in this change? Otherwise, I don't know how to test this change locally. How can I test that the added type annotations are correct?

@DebanKsahu

Copy link
Copy Markdown
Contributor Author

Yeah, I was planning to add type checking test at the end but, as you said I will add those test in the next commit. Should I go with Pyrefly?

@vstinner

Copy link
Copy Markdown
Member

Should I go with Pyrefly?

As you want, I don't have any preference.

@sergey-miryanov

Copy link
Copy Markdown
Contributor

I suggest using two or more type checkers (e.g., mypy and pyrefly). In my experience, I've encountered cases where pyrefly had a bug and missed a type error, while mypy caught it.

@DebanKsahu

Copy link
Copy Markdown
Contributor Author

I suggest using two or more type checkers (e.g., mypy and pyrefly). In my experience, I've encountered cases where pyrefly had a bug and missed a type error, while mypy caught it.

Sure then, I will go with pyrefly and mypy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Type System for pyperf

3 participants