Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GitPython: error: Module "git" does not explicitly export attribute "Repo" [attr-defined]

I am using Python 3.10.4, GitPython version 3.1.31, mypy version 1.4.1:

$ pip show GitPython
Name: GitPython
Version: 3.1.31
Location: /home/hakon/.pyenv/versions/3.10.4/lib/python3.10/site-packages
Requires: gitdb

$ python --version
Python 3.10.4

$ mypy --version
mypy 1.4.1 (compiled: yes)

If run mypy on this minimal example (git-python-types.py) :

import git
repo = git.Repo('some_dir')

I get the following error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$ mypy --strict git-python-types.py 
git-python-types.py:3: error: Module "git" does not explicitly export attribute "Repo"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

Any ideas on why this error occurs and how to fix it?

Some clues

I can see the following line in the GitPython source code :

from git.repo import Repo  # @NoMove @IgnorePep8

but I am not sure if mypy is reading this line or not.

>Solution :

As documentation suggests this is proper usage

https://gitpython.readthedocs.io/en/stable/tutorial.html#meet-the-repo-type

from git import Repo
...

then I would consider this a minor bug that should be fixed in GitPython.

You can work around this bug by importing it from the submodule

git.repo.Repo('some_dir')

or don’t use strict. The check it adds here is --no-implicit-reexport, which GitPython currently breaks.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading