-
Notifications
You must be signed in to change notification settings - Fork 795
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
Add type hints to tools.schemapi.schemapi #2614
Conversation
Thanks! Note the line at the top of the file: https://github.com/altair-viz/altair/blob/0217b2e73703d3b7b529b73b4dec9c17e7fb09bb/altair/utils/schemapi.py#L1-L2 You should make these changes in https://github.com/altair-viz/altair/blob/master/tools/schemapi/schemapi.py instead, and then run generate_schema_wrapper.py to sync the results to this file. |
@jakevdp got it! I'll make that change |
@joelostblom @jakevdp Here's the revised PoC |
Okay here are some of my attempts; I don't wanna go too much further just in case I'm way off track. Some of the types I have to infer based on my perusal of the code itself, but I may have missed something (e.g. whether or not certain variables are a |
Thanks for making this PR @thewchan and sorry there hasn't been any progress on reviewing it. I think having proper typing support would be great and it would also help us with some issues with tab completion in VS Code that we have been running up against lately (e.g. microsoft/pylance-release#3709 (reply in thread)). Do you have time to rebase this against the main branch of the repo, I see there have been some conflicts introduce and I would like to keep this PR alive and mergeable when there is time and expertise to review. Could you also add a @mattijn @ChristopherDavisUCI @binste Do you think this is something we should try to include for 5.0? It seems like a bigger change that should go in a bigger release like 5.0, but we also don't want to delay too long. Maybe it doesn't have to be in the first RC. Also, would anyone of you feel comfortable reviewing this? I am a bit hesitant expertise-wise personally. |
I agree, we should definitely try to keep this branch alive as a consistently typed library is great to work with and useful for projects which leverage tools like mypy. Thank you for the effort @thewchan! However, I don't think this PR is necessary to achieve #2918. I also don't know what the implications for IDEs and type checkers are if we add I'd suggest that we look at this in more detail after the release of version 5 and treat it as a bigger typing effort together with #2854 and providing type hints for the complete public interface, not just |
I'm happy to start over given the large amount of changes in the code base. Perhaps it make sense to start adding types incrementally in a way that makes the most sense. Let me know where I should start? |
I'll soon create a more detailed issue with a suggestion on how we could go about adding type hints to Altair + an overview of the different already opened issues, ideas, etc. I agree with @thewchan that it makes sense to do this incrementally. Given that you @thewchan already started on schemapi.py it would be great if you could finish the type hints for this file. Happy to review the updated PR. As we get the most out of type hints on the "public api"/often used functionality of Altair, I'd suggest to afterwards tackle |
Just fyi, I'm now working on a PR to add mypy as a linter to Altair and fix all current issues so that the current codebase passes. |
@joelostblom Here's a draft PR for type hints just for this one module as a proof-of-concept. Let me know what you think!