Skip to content

Commit

Permalink
Merge pull request #1760 from EliahKagan/noqa
Browse files Browse the repository at this point in the history
Overhaul noqa directives
  • Loading branch information
Byron authored Dec 9, 2023
2 parents 86fcb1b + 41d22b2 commit a58a6be
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 103 deletions.
27 changes: 13 additions & 14 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

# flake8: noqa
# @PydevCodeAnalysisIgnore

from git.exc import * # @NoMove @IgnorePep8
from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
from git.types import PathLike

__version__ = "git"

from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING

from gitdb.util import to_hex_sha
from git.exc import * # noqa: F403 # @NoMove @IgnorePep8
from git.types import PathLike

try:
from git.compat import safe_decode # @NoMove @IgnorePep8
from git.config import GitConfigParser # @NoMove @IgnorePep8
from git.objects import * # @NoMove @IgnorePep8
from git.refs import * # @NoMove @IgnorePep8
from git.diff import * # @NoMove @IgnorePep8
from git.db import * # @NoMove @IgnorePep8
from git.objects import * # noqa: F403 # @NoMove @IgnorePep8
from git.refs import * # noqa: F403 # @NoMove @IgnorePep8
from git.diff import * # noqa: F403 # @NoMove @IgnorePep8
from git.db import * # noqa: F403 # @NoMove @IgnorePep8
from git.cmd import Git # @NoMove @IgnorePep8
from git.repo import Repo # @NoMove @IgnorePep8
from git.remote import * # @NoMove @IgnorePep8
from git.index import * # @NoMove @IgnorePep8
from git.remote import * # noqa: F403 # @NoMove @IgnorePep8
from git.index import * # noqa: F403 # @NoMove @IgnorePep8
from git.util import ( # @NoMove @IgnorePep8
LockFile,
BlockingLockFile,
Expand All @@ -33,12 +32,12 @@
remove_password_if_present,
rmtree,
)
except GitError as _exc:
except GitError as _exc: # noqa: F405
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc

# __all__ must be statically defined by py.typed support
# __all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]
__all__ = [
__all__ = [ # noqa: F405
"Actor",
"AmbiguousObjectName",
"BadName",
Expand Down Expand Up @@ -127,7 +126,7 @@ def refresh(path: Optional[PathLike] = None) -> None:

if not Git.refresh(path=path):
return
if not FetchInfo.refresh():
if not FetchInfo.refresh(): # noqa: F405
return # type: ignore [unreachable]

GIT_OK = True
Expand Down
2 changes: 1 addition & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def execute(
# Only search PATH, not CWD. This must be in the *caller* environment. The "1" can be any value.
maybe_patch_caller_env = patch_env("NoDefaultCurrentDirectoryInExePath", "1")
else:
cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable
cmd_not_found_exception = FileNotFoundError
maybe_patch_caller_env = contextlib.nullcontext()
# END handle

Expand Down
9 changes: 2 additions & 7 deletions git/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@

"""Utilities to help provide compatibility with Python 3."""

# flake8: noqa

import locale
import os
import sys

from gitdb.utils.encoding import (
force_bytes, # @UnusedImport
force_text, # @UnusedImport
)
from gitdb.utils.encoding import force_bytes, force_text # noqa: F401 # @UnusedImport

# typing --------------------------------------------------------------------

from typing import (
from typing import ( # noqa: F401
Any,
AnyStr,
Dict,
Expand Down
6 changes: 2 additions & 4 deletions git/index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@

"""Initialize the index package."""

# flake8: noqa

from .base import *
from .typ import *
from .base import * # noqa: F401 F403
from .typ import * # noqa: F401 F403
20 changes: 9 additions & 11 deletions git/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@

"""Import all submodules' main classes into the package space."""

# flake8: noqa

import inspect

from .base import *
from .blob import *
from .commit import *
from .base import * # noqa: F403
from .blob import * # noqa: F403
from .commit import * # noqa: F403
from .submodule import util as smutil
from .submodule.base import *
from .submodule.root import *
from .tag import *
from .tree import *
from .submodule.base import * # noqa: F403
from .submodule.root import * # noqa: F403
from .tag import * # noqa: F403
from .tree import * # noqa: F403

# Fix import dependency - add IndexObject to the util module, so that it can be
# imported by the submodule.base.
smutil.IndexObject = IndexObject # type: ignore[attr-defined]
smutil.Object = Object # type: ignore[attr-defined]
smutil.IndexObject = IndexObject # type: ignore[attr-defined] # noqa: F405
smutil.Object = Object # type: ignore[attr-defined] # noqa: F405
del smutil

# Must come after submodule was made available.
Expand Down
14 changes: 7 additions & 7 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ def move(self, module_path: PathLike, configuration: bool = True, module: bool =
raise
# END handle undo rename

# Auto-rename submodule if it's name was 'default', that is, the checkout directory.
# Auto-rename submodule if its name was 'default', that is, the checkout directory.
if previous_sm_path == self.name:
self.rename(module_checkout_path)

Expand All @@ -976,19 +976,19 @@ def remove(
from the .gitmodules file and the entry in the .git/config file.
:param module: If True, the checked out module we point to will be deleted as
well.If that module is currently on a commit outside any branch in the
well. If that module is currently on a commit outside any branch in the
remote, or if it is ahead of its tracking branch, or if there are modified
or untracked files in its working tree, then the removal will fail.
In case the removal of the repository fails for these reasons, the
submodule status will not have been altered.
or untracked files in its working tree, then the removal will fail. In case
the removal of the repository fails for these reasons, the submodule status
will not have been altered.
If this submodule has child modules of its own, these will be deleted prior
to touching the direct submodule.
:param force: Enforces the deletion of the module even though it contains
modifications. This basically enforces a brute-force file system based
deletion.
:param configuration: If True, the submodule is deleted from the configuration,
otherwise it isn't. Although this should be enabled most of the time,
this flag enables you to safely delete the repository of your submodule.
otherwise it isn't. Although this should be enabled most of the time, this
flag enables you to safely delete the repository of your submodule.
:param dry_run: If True, we will not actually do anything, but throw the errors
we would usually throw.
:return: self
Expand Down
22 changes: 9 additions & 13 deletions git/objects/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,27 @@

"""General utility functions."""

# flake8: noqa F401


from abc import ABC, abstractmethod
import warnings
from git.util import IterableList, IterableObj, Actor

import re
import calendar
from collections import deque

from datetime import datetime, timedelta, tzinfo
from string import digits
import re
import time
import calendar
from datetime import datetime, timedelta, tzinfo
import warnings

from git.util import IterableList, IterableObj, Actor

# typing ------------------------------------------------------------
from typing import (
Any,
Callable,
Deque,
Iterator,
Generic,
# Generic,
NamedTuple,
overload,
Sequence, # NOQA: F401
Sequence,
TYPE_CHECKING,
Tuple,
Type,
Expand All @@ -38,7 +34,7 @@
cast,
)

from git.types import Has_id_attribute, Literal, _T # NOQA: F401
from git.types import Has_id_attribute, Literal # , _T

if TYPE_CHECKING:
from io import BytesIO, StringIO
Expand Down
13 changes: 6 additions & 7 deletions git/refs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

# flake8: noqa
# Import all modules in order, fix the names they require.

from .symbolic import *
from .reference import *
from .head import *
from .tag import *
from .remote import *
from .symbolic import * # noqa: F401 F403
from .reference import * # noqa: F401 F403
from .head import * # noqa: F401 F403
from .tag import * # noqa: F401 F403
from .remote import * # noqa: F401 F403

from .log import *
from .log import * # noqa: F401 F403
4 changes: 2 additions & 2 deletions git/refs/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
from git.types import PathLike

if TYPE_CHECKING:
from git.refs import SymbolicReference
from io import BytesIO
from git.config import GitConfigParser, SectionConstraint # NOQA
from git.refs import SymbolicReference
from git.config import GitConfigParser, SectionConstraint

# ------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions git/refs/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

# typing ------------------------------------------------------------------

from typing import Any, Callable, Iterator, Type, Union, TYPE_CHECKING # NOQA
from git.types import Commit_ish, PathLike, _T # NOQA
from typing import Any, Callable, Iterator, Type, Union, TYPE_CHECKING
from git.types import Commit_ish, PathLike, _T

if TYPE_CHECKING:
from git.repo import Repo
Expand Down
5 changes: 2 additions & 3 deletions git/refs/symbolic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

from git.types import PathLike
import os

from git.compat import defenc
Expand Down Expand Up @@ -31,8 +30,8 @@
Union,
TYPE_CHECKING,
cast,
) # NOQA
from git.types import Commit_ish, PathLike # NOQA
)
from git.types import Commit_ish, PathLike

if TYPE_CHECKING:
from git.repo import Repo
Expand Down
4 changes: 1 addition & 3 deletions git/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@

"""Initialize the Repo package."""

# flake8: noqa

from .base import Repo as Repo
from .base import Repo as Repo # noqa: F401
14 changes: 6 additions & 8 deletions git/types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

# flake8: noqa

import os
import sys
from typing import (
from typing import ( # noqa: F401
Dict,
NoReturn,
Sequence as Sequence,
Expand All @@ -16,24 +14,24 @@
Callable,
TYPE_CHECKING,
TypeVar,
) # noqa: F401
)

if sys.version_info >= (3, 8):
from typing import (
from typing import ( # noqa: F401
Literal,
TypedDict,
Protocol,
SupportsIndex as SupportsIndex,
runtime_checkable,
) # noqa: F401
)
else:
from typing_extensions import (
from typing_extensions import ( # noqa: F401
Literal,
SupportsIndex as SupportsIndex,
TypedDict,
Protocol,
runtime_checkable,
) # noqa: F401
)

# if sys.version_info >= (3, 10):
# from typing import TypeGuard # noqa: F401
Expand Down
8 changes: 4 additions & 4 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@
Has_id_attribute,
)

T_IterableObj = TypeVar("T_IterableObj", bound=Union["IterableObj", "Has_id_attribute"], covariant=True)
# So IterableList[Head] is subtype of IterableList[IterableObj]

# ---------------------------------------------------------------------

from gitdb.util import ( # NOQA @IgnorePep8
from gitdb.util import ( # noqa: F401 # @IgnorePep8
make_sha,
LockedFD, # @UnusedImport
file_contents_ro, # @UnusedImport
Expand All @@ -79,6 +76,9 @@
hex_to_bin, # @UnusedImport
)

T_IterableObj = TypeVar("T_IterableObj", bound=Union["IterableObj", "Has_id_attribute"], covariant=True)
# So IterableList[Head] is subtype of IterableList[IterableObj].

# NOTE: Some of the unused imports might be used/imported by others.
# Handle once test-cases are back up and running.
# Most of these are unused here, but are for use by git-python modules so these
Expand Down
4 changes: 2 additions & 2 deletions test/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

# flake8: noqa
import inspect
from .helper import *

from .helper import * # noqa: F401 F403

__all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]
4 changes: 2 additions & 2 deletions test/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def repo_creator(self):
os.chdir(rw_repo.working_dir)
try:
return func(self, rw_repo)
except: # noqa E722
except: # noqa: E722 B001
log.info("Keeping repo after failure: %s", repo_dir)
repo_dir = None
raise
Expand Down Expand Up @@ -305,7 +305,7 @@ def remote_repo_creator(self):
with cwd(rw_repo.working_dir):
try:
return func(self, rw_repo, rw_daemon_repo)
except: # noqa E722
except: # noqa: E722 B001
log.info(
"Keeping repos after failure: \n rw_repo_dir: %s \n rw_daemon_repo_dir: %s",
rw_repo_dir,
Expand Down
2 changes: 1 addition & 1 deletion test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def test_datetimes(self):
commit.authored_datetime,
datetime(2009, 10, 8, 18, 17, 5, tzinfo=tzoffset(-7200)),
commit.authored_datetime,
) # noqa
)
self.assertEqual(
commit.authored_datetime,
datetime(2009, 10, 8, 16, 17, 5, tzinfo=utc),
Expand Down
Loading

0 comments on commit a58a6be

Please sign in to comment.