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

explicitly list exported package symbols #1531

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alinsavix
Copy link

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:

#!/usr/bin/env python3
import gspread
gspread.service_account(filename="example.json")

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.

@alinsavix
Copy link
Author

I see the lint failures on this, but I would actually disagree with the linter in this case -- it's complaining that there are gaps (extra newlines) in the list of exportable symbols, but those gaps are there to work as separators between each individual source of symbols. If the gaps are removed, the comments showing where things are from end up looking more like commented-out list items than actual useful comments.

I'm happy to adjust to make the linter happy, though, if that's desired, just have to let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant