Pyright `reportInvalidTypeVarUse` warning on `BaseNeuralInference._wrap_builder`

Open
#2,276 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

@SatyamPandey-07 is already working on this.

Since Dec 1, 2026.

  • #2277 by @SatyamPandey-07 — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
30/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Stale
Tech stack
machine-learning, python

Research direction

Start with sbi/inference/trainers/base.py, where BaseNeuralInference._wrap_builder is defined, and review the generic bounds on BaseNeuralInference and NeuralInference. Check the existing linked pull request #2277 and the subclass call sites named in the issue before changing anything. Run uv run pyright sbi; done means the command reports zero errors and warnings and existing estimator subtype assignments still type-check.

Written by the indexing model from the issue text.

Description

Description

BaseNeuralInference._wrap_builder in sbi/inference/trainers/base.py is annotated to return Callable[[Tensor, Tensor], ConditionalEstimatorType]. However, BaseNeuralInference is generic over BaseConditionalEstimatorType (Generic[BaseConditionalEstimatorType]), not ConditionalEstimatorType. As a result, ConditionalEstimatorType appears only once in _wrap_builder's signature as an unbound TypeVar, triggering a Pyright reportInvalidTypeVarUse warning.

Steps to Reproduce

  1. Check out main (39bc3577).
  2. Run uv run pyright sbi.
  3. Observe the warning on sbi/inference/trainers/base.py:334:37.

Expected Behavior

uv run pyright sbi should complete with 0 errors, 0 warnings, 0 informations.

Actual Behavior / Error Logs

d:\GSOC\sbi\sbi\inference\trainers\base.py
  d:\GSOC\sbi\sbi\inference\trainers\base.py:334:37 - warning: TypeVar "ConditionalEstimatorType" appears only once in generic function signature
    Use "ConditionalEstimator" instead (reportInvalidTypeVarUse)
0 errors, 1 warning, 0 informations

Proposed Fix

Move _wrap_builder from BaseNeuralInference to NeuralInference, which is Generic[ConditionalEstimatorType]. All callers of _wrap_builder (nle_base.py, npe_a.py, npe_base.py, npe_pfn.py, nre_base.py, base_vf_inference.py) subclass NeuralInference, and moving it there binds ConditionalEstimatorType to the class without breaking subtype assignments such as NPE_A's Optional[ConditionalDensityEstimator].

Dominant language
Python
Stars
894
Forks
306
Avg merge
5d 21h
Merged PRs (30d)
61

Getting set up

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.

More from sbi-dev/sbi

All issues in sbi-dev/sbi

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.