Add type hints for Repository.branches, Repository.references and Repository.remotes#1384
Merged
jdavid merged 3 commits intolibgit2:masterfrom Jul 16, 2025
Merged
Add type hints for Repository.branches, Repository.references and Repository.remotes#1384jdavid merged 3 commits intolibgit2:masterfrom
jdavid merged 3 commits intolibgit2:masterfrom
Conversation
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.
Contributor
Author
|
I was not able to reproduce the failing pypy3.10 build on a fresh ubuntu 24.04 VM: Am I missing something or was this a CI hiccup? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After python/typeshed#14141 mypy no longer recognizes
Repository.branches,Repository.referencesandRepository.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.