-
Notifications
You must be signed in to change notification settings - Fork 317
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
Provide mypy stubs for the Python SDK #419
Comments
Thanks for sharing this. I'm passing this along as a feature request to the team. I can't promise if or when that might be implemented though. |
I think this would be great, in a strict mypy env the dropbox sdk is practically unusable due to mypy/pylance just inferring |
+1 from me, I was just about to file a bug about this. It looks like this in my VS Code (pylance). Each call takes extra time/research to figure out what is actually returned, and then some awkward workarounds to get it to work without type errors. I was surprised given Dropbox's support of Python typing in general. @samschott Do you have any pointers on how to generate stubs using stone? I only need stubs for a few APIs, but if it is easy to "mostly automatically" generate that sounds like an option. |
Sure. To generate the stubs yourself, you'll need to (1) install Dropbox's stone library and (2) clone the repo with Dropbox API spec files at https://github.com/dropbox/dropbox-api-spec. You then cd to the cloned directory and run: stone python_type_stubs OUTPUT_DIR *.stone -- --package dropbox This will generate stub files for all API endpoints ("routes") and their input and return types. This is incidentally very similar to the commands to generate the Python Dropbox SDK code itself which can be found in generate_base_client.py. |
Would it be possible to publish a new major version with type stubs then? |
Thanks! In case it helps anyone else, I was able to generate stubs in VS Code using the approach documented https://github.com/microsoft/pyright/blob/main/docs/type-stubs.md#generating-type-stubs. It took some fiddling to combine the APIs I used into a combined dropbox.pyi but now the APIs have proper return types! |
Thanks for sharing this! This is still open with the team, but I don't have an update on it. |
Hey folks! Sorry if this isn't the right place, but I wanted to add that I had success generating type stubs using mypy's $ MOD_PATH=$(python -c "import os, dropbox; print(os.path.dirname(dropbox.__file__))")
$ stubgen $MOD_PATH -o typings I preferred this to the methods above since it included the entire codebase, which doesn't seem to be the case with the API spec-based solution (the top-level I hope this is helpful, and again I apologize if this isn't the right place for this. This thread helped me get started towards this solution so I'm hoping to repay the favor. |
+1 for me please. it appears the correct thing to do is for the authors to create a |
Thanks for the feedback! |
Silly question, but could you easily fix this by adding a |
Adding |
Thanks for the notes! I can't myself offer a promise on if/how this might be addressed, but I've sent this along to the team. |
One last note, if the |
Thanks for the additional note! |
Why is this feature valuable to you? Does it solve a problem you're having?
Type checking of Python code can be incredibly helpful to write readable and maintainable code.
Describe the solution you'd like
Currently, these stubs can be mostly automatically generated from https://github.com/dropbox/dropbox-api-spec using stone. However, it would be convenient if you could make those stubs available as a separate package on
PyPItypeshed which gets updated with new releases of the SDK.The text was updated successfully, but these errors were encountered: