Skip to content

More typing#268

Draft
nstarman wants to merge 6 commits into
beartype:masterfrom
nstarman:more-typing
Draft

More typing#268
nstarman wants to merge 6 commits into
beartype:masterfrom
nstarman:more-typing

Conversation

@nstarman
Copy link
Copy Markdown
Collaborator

@nstarman nstarman commented May 8, 2026

Improves the typing.
One API change is that parametric can't take None anymore. It couldn't before, but now it really can't.

nstarman added 2 commits May 8, 2026 18:24
Add `@overload` signatures to `Function.__get__` so type checkers can distinguish class-level access (returns `Function`) from instance-level access (returns `MethodType`).

Add `tests/static/function_get.pyi` with `assert_type` checks covering both access modes and the `@plum.dispatch` return-type preservation.

Signed-off-by: nstarman <nstarman@users.noreply.github.com>
Introduces `_BoundFunctionProto` as the declared type of `_BoundFunction._f`
instead of `Function` directly. This prevents mypy from applying
`Function.__get__`'s descriptor protocol when resolving instance-attribute
accesses of `_f`, eliminating the need for `# type: ignore[union-attr]`
and `# type: ignore[return-value]` suppressions in `_BoundFunction`.

Signed-off-by: nstarman <nstarman@users.noreply.github.com>
@nstarman nstarman requested a review from wesselb May 8, 2026 22:55
@coveralls
Copy link
Copy Markdown

coveralls commented May 8, 2026

Coverage Report for CI Build 25586489844

Coverage decreased (-0.009%) to 99.497%

Details

  • Coverage decreased (-0.009%) from the base build.
  • Patch coverage: 47 of 47 lines across 3 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 995
Covered Lines: 990
Line Coverage: 99.5%
Coverage Strength: 6.75 hits per line

💛 - Coveralls

Signed-off-by: nstarman <nstarman@users.noreply.github.com>
…checks

Add return types and parameter annotations to `ParametricTypeMeta` methods, `CovariantMeta` methods, and helpers in `_parametric.py`. Also add `_parametric.py` to the mypy-checked files list in `pyproject.toml`.

Signed-off-by: nstarman <nstarman@users.noreply.github.com>
- Replace `cast(Callable[..., type], meta)(...)` with direct `meta(...)` calls using `meta: Any`
- Access `__new__` via intermediate `_new: Any` variable to satisfy mypy descriptor checks
- Remove stray blank line after docstring

Signed-off-by: nstarman <nstarman@users.noreply.github.com>
Copy link
Copy Markdown
Member

@wesselb wesselb left a comment

Choose a reason for hiding this comment

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

Looks great!! Left a few questions. Besides the questions, happy to merge whenever you're happy too :)

Comment thread src/plum/_function.py Outdated
Comment thread src/plum/_parametric.py Outdated
Comment thread src/plum/_function.py
Comment thread src/plum/_parametric.py
Co-authored-by: Wessel <wessel.p.bruinsma@gmail.com>
@nstarman nstarman marked this pull request as draft May 20, 2026 00:28
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.

3 participants