Skip to content

Fix some disallow_untyped_defs #1407

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

Merged
merged 1 commit into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pygit2/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#
# Utility functions to get the paths required for building extensions
#
def _get_libgit2_path():
def _get_libgit2_path() -> Path:
# LIBGIT2 environment variable takes precedence
libgit2_path = os.getenv('LIBGIT2')
if libgit2_path is not None:
Expand All @@ -52,7 +52,7 @@ def _get_libgit2_path():
return Path('/usr/local')


def get_libgit2_paths():
def get_libgit2_paths() -> tuple[Path, dict[str, list[str]]]:
# Base path
path = _get_libgit2_path()

Expand All @@ -61,7 +61,7 @@ def get_libgit2_paths():
if libgit2_lib is None:
library_dirs = [path / 'lib', path / 'lib64']
else:
library_dirs = [libgit2_lib]
library_dirs = [Path(libgit2_lib)]

include_dirs = [path / 'include']
return (
Expand Down
2 changes: 1 addition & 1 deletion pygit2/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def readinto(self, b, /):
except KeyboardInterrupt:
return 0

def close(self):
def close(self) -> None:
try:
self._ready.wait()
self._writer_closed.wait()
Expand Down
4 changes: 2 additions & 2 deletions pygit2/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
value_errors = set([C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS])


def check_error(err, io=False):
def check_error(err, io: bool = False) -> None:
if err >= 0:
return

Expand Down Expand Up @@ -69,5 +69,5 @@ def check_error(err, io=False):

# Indicate that we want libgit2 to pretend a function was not set
class Passthrough(Exception):
def __init__(self):
def __init__(self) -> None:
super().__init__('The function asked for pass-through')
2 changes: 1 addition & 1 deletion pygit2/refspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class Refspec:
"""The constructor is for internal use only."""

def __init__(self, owner, ptr):
def __init__(self, owner, ptr) -> None:
self._owner = owner
self._refspec = ptr

Expand Down
4 changes: 2 additions & 2 deletions pygit2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def to_bytes(
return s.encode(encoding, errors) # type: ignore[union-attr]


def to_str(s):
def to_str(s: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -> str:
if hasattr(s, '__fspath__'):
s = os.fspath(s)

Expand Down Expand Up @@ -110,7 +110,7 @@ def new_git_strarray() -> Generator['GitStrrayC', None, None]:
C.git_strarray_dispose(strarray)


def strarray_to_strings(arr):
def strarray_to_strings(arr) -> list[str]:
"""
Return a list of strings from a git_strarray pointer.

Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@


class sdist_files_from_git(sdist):
def get_file_list(self):
def get_file_list(self) -> None:
popen = Popen(
['git', 'ls-files'], stdout=PIPE, stderr=PIPE, universal_newlines=True
)
Expand All @@ -56,7 +56,7 @@ def get_file_list(self):
print(stderrdata)
sys.exit()

def exclude(line):
def exclude(line: str) -> bool:
for prefix in ['.', 'appveyor.yml', 'docs/', 'misc/']:
if line.startswith(prefix):
return True
Expand Down Expand Up @@ -97,11 +97,11 @@ def exclude(line):

# On Windows, we install the git2.dll too.
class BuildWithDLLs(build):
def _get_dlls(self):
def _get_dlls(self) -> list[tuple[Path, Path]]:
# return a list of (FQ-in-name, relative-out-name) tuples.
ret = []
bld_ext = self.distribution.get_command_obj('build_ext')
compiler_type = bld_ext.compiler.compiler_type
compiler_type = bld_ext.compiler.compiler_type # type: ignore[attr-defined]
libgit2_dlls = []
if compiler_type == 'msvc':
libgit2_dlls.append('git2.dll')
Expand All @@ -121,7 +121,7 @@ def _get_dlls(self):
log.debug(f'(looked in {look_dirs})')
return ret

def run(self):
def run(self) -> None:
build.run(self)
for s, d in self._get_dlls():
self.copy_file(s, d)
Expand Down
Loading