Skip to content

Fix warning in Pyright ("Repo" not exported from module "git") #1656

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
DeflateAwning opened this issue Sep 12, 2023 · 3 comments
Closed

Fix warning in Pyright ("Repo" not exported from module "git") #1656

DeflateAwning opened this issue Sep 12, 2023 · 3 comments

Comments

@DeflateAwning
Copy link
Contributor

DeflateAwning commented Sep 12, 2023

In Pyright, the following line of code causes the following error:

import git
gitRepo = git.Repo(__file__)

Error:
image

@EliahKagan
Copy link
Member

I think this happens because git.__all__ is built dynamically:

__all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]

Although "Repo" is in it, it's not given literally, and with pyright being a static analyzer, it cannot figure that out.

There are some other places where * imports are used that I expect might produce a similar effect, albeit for attributes that might be absent rather than attributes that might be considered private.

@Byron
Copy link
Member

Byron commented Sep 12, 2023

Thanks for posting, and thanks for the analysis @EliahKagan!

Spelling out __all__ should be easy enough and since GitPython is very stable, I don't think maintaining it would be a problem anymore. Since GitPython started to support type annotation, I think it's worth it to try make it even more useful, to get more mileage out of it.

@DeflateAwning
Copy link
Contributor Author

This issue is resolved with #1659

# for free to join this conversation on GitHub. Already have an account? # to comment
Development

No branches or pull requests

3 participants