Pyright `reportInvalidTypeVarUse` warning on `BaseNeuralInference._wrap_builder`
Maintainers usually reply within 6 days
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
- Domain
- machine-learning
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
- Check out
main(39bc3577). - Run
uv run pyright sbi. - 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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sbi-dev/sbi
-
simulate_for_sbi(num_simulations=0) returns 1D empty theta/x tensors and breaks append_simulationsOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
sbi-dev/sbi#2310 · 3 comments ·
Maintainers usually reply within 6 days
-
bug: RestrictionEstimator.train(subsample_invalid_sims="auto") raises TypeErrorPossibly taken @Nitesh780 claimed this 2 days ago. Openbug
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
sbi-dev/sbi#2309 · 1 comment ·
Maintainers usually reply within 6 days
-
TARP reference sampling fails when a parameter coordinate is fixedPossibly taken @Jayant-kernel claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
sbi-dev/sbi#2264 · 2 comments ·
Maintainers usually reply within 6 days
-
fix: broadcast UniformNormalConvolution batch shapePossibly taken @studentarijitpaul claimed this 32 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
sbi-dev/sbi#2151 · 2 comments ·
Maintainers usually reply within 6 days
-
bug
sbi-dev/sbi#2321 · 1 comment ·
Maintainers usually reply within 6 days
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day