explicitly list exported package symbols #1531
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, gspread uses implied exports for all of its externally-accessible symbols. This works fine, but it makes some type checkers complain. In particular, pylance (the default type checker for python in VSCode) flags an issue. mypy will as well, if run with the
--no-implicit-reexport
.The following script can be used to see this in action:
pylance will return this warning:
"service_account" is not exported from module "gspread"
mypy --no-implicit-reexport will return:
error: Module "gspread" does not explicitly export attribute "service_account" [attr-defined]
Some brief notes about implicit and explicit exports are available in the mypy documentation, see e.g. https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport . The choices for fixing this problem are to either use the "from-as" import format for all the symbols in the top level
__init__.py
file, or to explicitly list all of the intended exports explicitly in an__all__
list in that file. I've chosen the latter of those two choices, as it is generally good form to do so.There should be no actual behavior change with this patch beyond making fewer red lines in peoples' editors.