Skip to content
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

typecheck-part-1 #1350

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath('..')) # noqa: PTH100


# -- Project information -----------------------------------------------------
37 changes: 19 additions & 18 deletions pygit2/__init__.py
Original file line number Diff line number Diff line change
@@ -35,38 +35,39 @@

# High level API
from . import enums
from ._build import __version__
from .blame import Blame, BlameHunk
from .blob import BlobIO
from .callbacks import Payload, RemoteCallbacks, CheckoutCallbacks, StashApplyCallbacks
from .callbacks import git_clone_options, git_fetch_options, get_credentials
from .config import Config
from .credentials import *
from .errors import check_error, Passthrough
from ._build import __version__ # noqa: F401
from .blame import Blame, BlameHunk # noqa: F401
from .blob import BlobIO # noqa: F401
from .callbacks import Payload, RemoteCallbacks, CheckoutCallbacks, StashApplyCallbacks # noqa: F401
from .callbacks import git_clone_options, git_fetch_options, get_credentials # noqa: F401
from .config import Config # noqa: F401
from .credentials import * # noqa: F403
from .errors import check_error, Passthrough # noqa: F401
from .ffi import ffi, C
from .filter import Filter
from .index import Index, IndexEntry
from .legacyenums import *
from .packbuilder import PackBuilder
from .remotes import Remote
from .filter import Filter # noqa: F401
from .index import Index, IndexEntry # noqa: F401
from .legacyenums import * # noqa: F403
from .packbuilder import PackBuilder # noqa: F401
from .remotes import Remote # noqa: F401
from .repository import Repository
from .settings import Settings
from .submodules import Submodule
from .submodules import Submodule # noqa: F401
from .utils import to_bytes, to_str


# Features
features = enums.Feature(C.git_libgit2_features())

# libgit version tuple
LIBGIT2_VER = (LIBGIT2_VER_MAJOR, LIBGIT2_VER_MINOR, LIBGIT2_VER_REVISION)
LIBGIT2_VER = (LIBGIT2_VER_MAJOR, LIBGIT2_VER_MINOR, LIBGIT2_VER_REVISION) # noqa: F405

# Let _pygit2 cache references to Python enum types.
# This is separate from PyInit__pygit2() to avoid a circular import.
_cache_enums()


def init_repository(

def init_repository( # noqa: PLR0913
path: typing.Union[str, bytes, os.PathLike, None],
bare: bool = False,
flags: enums.RepositoryInitFlag = enums.RepositoryInitFlag.MKPATH,
@@ -144,7 +145,7 @@ def init_repository(
return Repository(to_str(path))


def clone_repository(
def clone_repository( # noqa: PLR0913
url,
path,
bare=False,
@@ -221,6 +222,6 @@ def clone_repository(
return Repository._from_c(crepo[0], owned=True)


tree_entry_key = functools.cmp_to_key(tree_entry_cmp)
tree_entry_key = functools.cmp_to_key(tree_entry_cmp) # noqa: F405

settings = Settings()
2 changes: 1 addition & 1 deletion pygit2/_build.py
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ def _get_libgit2_path():

# Default
if os.name == 'nt':
return Path(r'%s\libgit2' % os.getenv('ProgramFiles'))
return Path(r'%s\libgit2' % os.getenv('ProgramFiles')) # noqa: SIM112
return Path('/usr/local')


4 changes: 2 additions & 2 deletions pygit2/_pygit2.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterator, Literal, Optional, overload
from typing import Iterator, Literal, Optional, overload # noqa: I001
from io import IOBase
from . import Index
from .enums import (
@@ -42,7 +42,7 @@ class Object:
oid: Oid
raw_name: bytes | None
short_id: str
type: 'Literal[GIT_OBJ_COMMIT] | Literal[GIT_OBJ_TREE] | Literal[GIT_OBJ_TAG] | Literal[GIT_OBJ_BLOB]'
type: 'Literal[GIT_OBJ_COMMIT] | Literal[GIT_OBJ_TREE] | Literal[GIT_OBJ_TAG] | Literal[GIT_OBJ_BLOB]' # noqa: E501
type_str: "Literal['commit'] | Literal['tree'] | Literal['tag'] | Literal['blob']"
@overload
def peel(self, target_type: 'Literal[GIT_OBJ_COMMIT]') -> 'Commit': ...
4 changes: 2 additions & 2 deletions pygit2/_run.py
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
"""

# Import from the Standard Library
import codecs
import codecs # noqa: I001
from pathlib import Path
import sys

@@ -85,7 +85,7 @@
]
h_source = []
for h_file in h_files:
h_file = dir_path / 'decl' / h_file
h_file = dir_path / 'decl' / h_file # noqa: PLW2901
with codecs.open(h_file, 'r', 'utf-8') as f:
h_source.append(f.read())

2 changes: 1 addition & 1 deletion pygit2/blame.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
# Boston, MA 02110-1301, USA.

# Import from pygit2
from .ffi import ffi, C
from .ffi import ffi, C # noqa: I001
from .utils import GenericIterator
from ._pygit2 import Signature, Oid

2 changes: 1 addition & 1 deletion pygit2/blob.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import io
import io # noqa: I001
import threading
import time
from contextlib import AbstractContextManager
2 changes: 1 addition & 1 deletion pygit2/branches.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

from __future__ import annotations
from __future__ import annotations # noqa: I001
from typing import TYPE_CHECKING

from .enums import BranchType, ReferenceType
20 changes: 10 additions & 10 deletions pygit2/callbacks.py
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@
"""

# Standard Library
from contextlib import contextmanager
from contextlib import contextmanager # noqa: I001
from functools import wraps
from typing import Optional, Union

@@ -133,9 +133,9 @@ def sideband_progress(self, string: str) -> None:

def credentials(
self,
url: str,
username_from_url: Union[str, None],
allowed_types: CredentialType,
url: str, # noqa: ARG002
username_from_url: Union[str, None], # noqa: ARG002
allowed_types: CredentialType, # noqa: ARG002
):
"""
Credentials callback. If the remote server requires authentication,
@@ -159,7 +159,7 @@ def credentials(
"""
raise Passthrough

def certificate_check(self, certificate: None, valid: bool, host: str) -> bool:
def certificate_check(self, certificate: None, valid: bool, host: str) -> bool: # noqa: ARG002
"""
Certificate callback. Override with your own function to determine
whether to accept the server's certificate.
@@ -493,7 +493,7 @@ def _certificate_check_cb(cert_i, valid, host, data):
if not val:
return C.GIT_ECERTIFICATE
except Passthrough:
if is_ssh:
if is_ssh: # noqa: SIM114
return 0
elif valid:
return 0
@@ -667,15 +667,15 @@ def get_credentials(fn, url, username, allowed):


@libgit2_callback
def _checkout_notify_cb(
def _checkout_notify_cb( # noqa: PLR0913
why, path_cstr, baseline, target, workdir, data: CheckoutCallbacks
):
pypath = maybe_string(path_cstr)
pybaseline = DiffFile.from_c(ptr_to_bytes(baseline))
pytarget = DiffFile.from_c(ptr_to_bytes(target))
pyworkdir = DiffFile.from_c(ptr_to_bytes(workdir))

try:
try: # noqa: SIM105
data.checkout_notify(why, pypath, pybaseline, pytarget, pyworkdir)
except Passthrough:
# Unlike most other operations with optional callbacks, checkout
@@ -701,7 +701,7 @@ def _git_checkout_options(
paths=None,
c_checkout_options_ptr=None,
):
if callbacks is None:
if callbacks is None: # noqa: SIM108
payload = CheckoutCallbacks()
else:
payload = callbacks
@@ -768,7 +768,7 @@ def git_checkout_options(callbacks=None, strategy=None, directory=None, paths=No

@libgit2_callback
def _stash_apply_progress_cb(progress: StashApplyProgress, data: StashApplyCallbacks):
try:
try: # noqa: SIM105
data.stash_apply_progress(progress)
except Passthrough:
# Unlike most other operations with optional callbacks, stash apply
4 changes: 2 additions & 2 deletions pygit2/config.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
from cached_property import cached_property

# Import from pygit2
from .errors import check_error
from .errors import check_error # noqa: I001
from .ffi import ffi, C
from .utils import to_bytes

@@ -93,7 +93,7 @@ def from_c(cls, repo, ptr):
return config

def __del__(self):
try:
try: # noqa: SIM105
C.git_config_free(self._config)
except AttributeError:
pass
2 changes: 1 addition & 1 deletion pygit2/credentials.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

from __future__ import annotations
from __future__ import annotations # noqa: I001

from typing import TYPE_CHECKING

14 changes: 7 additions & 7 deletions pygit2/enums.py
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ class BlameFlag(IntFlag):
'Not yet implemented and reserved for future use (as of libgit2 1.9.0).'

FIRST_PARENT = _pygit2.GIT_BLAME_FIRST_PARENT
'Restrict the search of commits to those reachable following only the first parents.'
'Restrict the search of commits to those reachable following only the first parents.' # noqa: E501

USE_MAILMAP = _pygit2.GIT_BLAME_USE_MAILMAP
"""
@@ -95,7 +95,7 @@ class BlobFilter(IntFlag):
'Do not apply filters to binary files.'

NO_SYSTEM_ATTRIBUTES = _pygit2.GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES
'Filters will not load configuration from the system-wide `gitattributes` in `/etc` (or system equivalent).'
'Filters will not load configuration from the system-wide `gitattributes` in `/etc` (or system equivalent).' # noqa: E501

ATTRIBUTES_FROM_HEAD = _pygit2.GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD
'Load filters from a `.gitattributes` file in the HEAD commit.'
@@ -246,7 +246,7 @@ class ConfigLevel(IntEnum):
'XDG compatible configuration file; typically ~/.config/git/config'

GLOBAL = _pygit2.GIT_CONFIG_LEVEL_GLOBAL
'User-specific configuration file (also called Global configuration file); typically ~/.gitconfig'
'User-specific configuration file (also called Global configuration file); typically ~/.gitconfig' # noqa: E501

LOCAL = _pygit2.GIT_CONFIG_LEVEL_LOCAL
'Repository specific configuration file; $WORK_DIR/.git/config on non-bare repos'
@@ -642,7 +642,7 @@ class DiffStatsFormat(IntFlag):
'Number statistics, equivalent of `--numstat`'

INCLUDE_SUMMARY = _pygit2.GIT_DIFF_STATS_INCLUDE_SUMMARY
'Extended header information such as creations, renames and mode changes, equivalent of `--summary`'
'Extended header information such as creations, renames and mode changes, equivalent of `--summary`' # noqa: E501


class Feature(IntFlag):
@@ -726,7 +726,7 @@ class FilterFlag(IntFlag):
'Load attributes from `.gitattributes` in the root of HEAD'

ATTRIBUTES_FROM_COMMIT = _pygit2.GIT_FILTER_ATTRIBUTES_FROM_COMMIT
'Load attributes from `.gitattributes` in a given commit. This can only be specified in a `git_filter_options`.'
'Load attributes from `.gitattributes` in a given commit. This can only be specified in a `git_filter_options`.' # noqa: E501


class FilterMode(IntEnum):
@@ -947,7 +947,7 @@ class ObjectType(IntEnum):
class Option(IntEnum):
"""Global libgit2 library options"""

# Commented out values --> exists in libgit2 but not supported in pygit2's options.c yet
# Commented out values --> exists in libgit2 but not supported in pygit2's options.c yet # noqa: E501
GET_MWINDOW_SIZE = _pygit2.GIT_OPT_GET_MWINDOW_SIZE
SET_MWINDOW_SIZE = _pygit2.GIT_OPT_SET_MWINDOW_SIZE
GET_MWINDOW_MAPPED_LIMIT = _pygit2.GIT_OPT_GET_MWINDOW_MAPPED_LIMIT
@@ -1293,7 +1293,7 @@ class SubmoduleStatus(IntFlag):
'submodule workdir index is dirty (flag available if ignore is NONE or UNTRACKED)'

WD_WD_MODIFIED = _pygit2.GIT_SUBMODULE_STATUS_WD_WD_MODIFIED
'submodule workdir has modified files (flag available if ignore is NONE or UNTRACKED)'
'submodule workdir has modified files (flag available if ignore is NONE or UNTRACKED)' # noqa: E501

WD_UNTRACKED = _pygit2.GIT_SUBMODULE_STATUS_WD_UNTRACKED
'submodule workdir contains untracked files (flag available if ignore is NONE)'
6 changes: 3 additions & 3 deletions pygit2/errors.py
Original file line number Diff line number Diff line change
@@ -24,19 +24,19 @@
# Boston, MA 02110-1301, USA.

# Import from pygit2
from .ffi import ffi, C
from .ffi import ffi, C # noqa: I001
from ._pygit2 import GitError


value_errors = set([C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS])
value_errors = set([C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS]) # noqa: C405


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

# These are special error codes, they should never reach here
test = err != C.GIT_EUSER and err != C.GIT_PASSTHROUGH
test = err != C.GIT_EUSER and err != C.GIT_PASSTHROUGH # noqa: PLR1714
assert test, f'Unexpected error code {err}'

# Error message
3 changes: 2 additions & 1 deletion pygit2/ffi.py
Original file line number Diff line number Diff line change
@@ -24,4 +24,5 @@
# Boston, MA 02110-1301, USA.

# Import from pygit2
from ._libgit2 import ffi, lib as C # noqa: F401

from ._libgit2 import ffi, lib as C # noqa: I001, F401
2 changes: 1 addition & 1 deletion pygit2/filter.py
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ def check(self, src: FilterSource, attr_values: List[Optional[str]]):
"""

def write(
self, data: bytes, src: FilterSource, write_next: Callable[[bytes], None]
self, data: bytes, src: FilterSource, write_next: Callable[[bytes], None] # noqa: ARG002
):
"""
Write input `data` to this filter.
6 changes: 3 additions & 3 deletions pygit2/index.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

import warnings
import warnings # noqa: I001
import weakref

# Import from pygit2
@@ -367,15 +367,15 @@ def oid(self):
@property
def hex(self):
"""The id of the referenced object as a hex string"""
warnings.warn('Use str(entry.id)', DeprecationWarning)
warnings.warn('Use str(entry.id)', DeprecationWarning) # noqa: B028
return str(self.id)

def __str__(self):
return f'<path={self.path} id={self.id} mode={self.mode}>'

def __repr__(self):
t = type(self)
return f'<{t.__module__}.{t.__qualname__} path={self.path} id={self.id} mode={self.mode}>'
return f'<{t.__module__}.{t.__qualname__} path={self.path} id={self.id} mode={self.mode}>' # noqa: E501

def __eq__(self, other):
if self is other:
2 changes: 1 addition & 1 deletion pygit2/packbuilder.py
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@


# Import from pygit2
from .errors import check_error
from .errors import check_error # noqa: I001
from .ffi import ffi, C
from .utils import to_bytes

Loading
Oops, something went wrong.
Loading
Oops, something went wrong.