diff --git a/pygit2/_build.py b/pygit2/_build.py index 4232605b..da4c34b2 100644 --- a/pygit2/_build.py +++ b/pygit2/_build.py @@ -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: @@ -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() @@ -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 ( diff --git a/pygit2/blob.py b/pygit2/blob.py index 1232fb2f..1ee6a9eb 100644 --- a/pygit2/blob.py +++ b/pygit2/blob.py @@ -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() diff --git a/pygit2/errors.py b/pygit2/errors.py index 72a4af39..3ddf71eb 100644 --- a/pygit2/errors.py +++ b/pygit2/errors.py @@ -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 @@ -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') diff --git a/pygit2/refspec.py b/pygit2/refspec.py index cb900e75..794e8d13 100644 --- a/pygit2/refspec.py +++ b/pygit2/refspec.py @@ -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 diff --git a/pygit2/utils.py b/pygit2/utils.py index b3d5d141..22fde943 100644 --- a/pygit2/utils.py +++ b/pygit2/utils.py @@ -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) @@ -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. diff --git a/setup.py b/setup.py index ff904fa9..2bd62f90 100644 --- a/setup.py +++ b/setup.py @@ -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 ) @@ -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 @@ -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') @@ -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)