Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type overloading for return_inferencedata in sample #6709

Merged
merged 2 commits into from
May 12, 2023

Conversation

thomasaarholt
Copy link
Contributor

@thomasaarholt thomasaarholt commented May 8, 2023

What is this PR about?
This PR adds typing support which lets a type checker (like mypy or vscode's pylance) infer that when when passing pm.sample(return_inferencedata=True), then the return type is InferenceData, and when return_inferencedata=False, it is MultiTrace. This helps later on when referring to methods or properties that only exist on one of the two types.

Checklist

Maintenance

Added typing support to let a type checker (like mypy or vscode's pylance) infer that when passing pm.sample(return_inferencedata=True), then the return type is InferenceData, and when return_inferencedata=False, it is MultiTrace.


📚 Documentation preview 📚: https://pymc--6709.org.readthedocs.build/en/6709/

@codecov
Copy link

codecov bot commented May 8, 2023

Codecov Report

Merging #6709 (c3b9b20) into main (a617bf2) will decrease coverage by 1.86%.
The diff coverage is 71.42%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6709      +/-   ##
==========================================
- Coverage   89.57%   87.71%   -1.86%     
==========================================
  Files          95       95              
  Lines       16131    16141      +10     
==========================================
- Hits        14449    14158     -291     
- Misses       1682     1983     +301     
Impacted Files Coverage Δ
pymc/sampling/mcmc.py 89.81% <71.42%> (-0.32%) ⬇️

... and 12 files with indirect coverage changes

@thomasaarholt
Copy link
Contributor Author

Mypy is failing with

pymc/sampling/mcmc.py:333: error: Overloaded function signatures 1 and 2 overlap with incompatible return types

Pyright (pyright pymc/sampling/mcmc.py) does not raise an error, and I'm inclined to believe that it is more accurate than mypy for this. If pymc-devs disagree, I'm happy to take any advice.

@thomasaarholt
Copy link
Contributor Author

I fixed mypy, looks like it couldn't infer the same that pyright could.

@ricardoV94 ricardoV94 requested a review from michaelosthege May 10, 2023 20:48
Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

I never knew how to do this, so thanks for showing!

@michaelosthege michaelosthege merged commit f632a34 into pymc-devs:main May 12, 2023
@ricardoV94 ricardoV94 changed the title Type overloading for return_inferencedata in pm.sample() Type overloading for return_inferencedata in sample May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants