Skip to content

Conversation

BenediktSeidl
Copy link
Contributor

After python/typeshed#14141 mypy no longer recognizes Repository.branches, Repository.references and Repository.remotes.

This pull request adds the type hints directly to pygit2.

Maybe it would have been possible to copy the type hints from the typeshed repo, but I'm not sure how this would work out with the licensees. My changes are a independent implementation.

pygit2 was removed from the python typeshed, but the built in types of
pygit2 are not complete.

This change tries to improve this situation, by fixing type errors that
occur when activating typing for the tests.
So first the test functions (for the public API) in test/test_refs.py
were adapted, in order to activate mypy type checking.
Then _pygit2.pyi was adapted to fix those mypy type checking errors.

The skeleton was provided by:
    stubgen -m pygit2.references -o /tmp/pygit2

The following command
    mypy test
returned the following summary before this change:
    Found 289 errors in 10 files (checked 50 source files)
and after this change:
    Found 289 errors in 10 files (checked 50 source files)
The following command
    mypy test
reports
    Found 284 errors in 9 files (checked 50 source files)
after this change.
The following command
    mypy test
reports
    Found 280 errors in 8 files (checked 50 source files)
after this change.
@BenediktSeidl
Copy link
Contributor Author

I was not able to reproduce the failing pypy3.10 build on a fresh ubuntu 24.04 VM:

sudo apt-get install git build-essential cmake libssl-dev

export LIBGIT2=~/prefix/
mkdir $LIBGIT2
export LD_LIBRARY_PATH=~/prefix/lib

wget https://downloads.python.org/pypy/pypy3.10-v7.3.19-linux64.tar.bz2
bzip2 -d pypy3.10-v7.3.19-linux64.tar.bz2 
tar -xf pypy3.10-v7.3.19-linux64.tar 
./pypy3.10-v7.3.19-linux64/bin/python -mvenv venv-pypy-7.3.19
source venv-pypy-7.3.19/bin/activate
pip install pytest

git clone --branch v1.9.1 https://github.com/libgit2/libgit2.git
cd libgit2
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$LIBGIT2
cmake --build . --target install
cd ../../

git clone --branch typing https://github.com/BenediktSeidl/pygit2.git
cd pygit2
pip install .
pytest test

Am I missing something or was this a CI hiccup?

@jdavid jdavid merged commit 375f238 into libgit2:master Jul 16, 2025
15 of 20 checks passed
@BenediktSeidl BenediktSeidl deleted the typing branch July 16, 2025 10:50
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