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 2 commits 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.

@alifeee
Copy link
Collaborator

alifeee commented Dec 9, 2024

hi ! sorry for the delay

this is a great addition :)

it will be very helpful for automatic code completers

I agree with you on the linter. If you feel you can change it so it doesn't complain, then great ;)

@alinsavix
Copy link
Author

I can change it so it doesn't complain, but that would require removing the whitespace that makes it more readable, so might not be desirable. Which way would you prefer?

@alifeee
Copy link
Collaborator

alifeee commented Dec 10, 2024

I have ignored __init__.py from the linting, as I don't think it's important that this file be formatted strictly. This is more for our code files.

With that, I am happy to merge this :)

I will let @lavigne958 merge this ;]

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.

2 participants