Skip to content

Commit a58a6be

Browse files
authored
Merge pull request #1760 from EliahKagan/noqa
Overhaul noqa directives
2 parents 86fcb1b + 41d22b2 commit a58a6be

23 files changed

+83
-103
lines changed

git/__init__.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,27 @@
33
# This module is part of GitPython and is released under the
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

6-
# flake8: noqa
76
# @PydevCodeAnalysisIgnore
87

9-
from git.exc import * # @NoMove @IgnorePep8
10-
from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
11-
from git.types import PathLike
12-
138
__version__ = "git"
149

10+
from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
11+
1512
from gitdb.util import to_hex_sha
13+
from git.exc import * # noqa: F403 # @NoMove @IgnorePep8
14+
from git.types import PathLike
1615

1716
try:
1817
from git.compat import safe_decode # @NoMove @IgnorePep8
1918
from git.config import GitConfigParser # @NoMove @IgnorePep8
20-
from git.objects import * # @NoMove @IgnorePep8
21-
from git.refs import * # @NoMove @IgnorePep8
22-
from git.diff import * # @NoMove @IgnorePep8
23-
from git.db import * # @NoMove @IgnorePep8
19+
from git.objects import * # noqa: F403 # @NoMove @IgnorePep8
20+
from git.refs import * # noqa: F403 # @NoMove @IgnorePep8
21+
from git.diff import * # noqa: F403 # @NoMove @IgnorePep8
22+
from git.db import * # noqa: F403 # @NoMove @IgnorePep8
2423
from git.cmd import Git # @NoMove @IgnorePep8
2524
from git.repo import Repo # @NoMove @IgnorePep8
26-
from git.remote import * # @NoMove @IgnorePep8
27-
from git.index import * # @NoMove @IgnorePep8
25+
from git.remote import * # noqa: F403 # @NoMove @IgnorePep8
26+
from git.index import * # noqa: F403 # @NoMove @IgnorePep8
2827
from git.util import ( # @NoMove @IgnorePep8
2928
LockFile,
3029
BlockingLockFile,
@@ -33,12 +32,12 @@
3332
remove_password_if_present,
3433
rmtree,
3534
)
36-
except GitError as _exc:
35+
except GitError as _exc: # noqa: F405
3736
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc
3837

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

128127
if not Git.refresh(path=path):
129128
return
130-
if not FetchInfo.refresh():
129+
if not FetchInfo.refresh(): # noqa: F405
131130
return # type: ignore [unreachable]
132131

133132
GIT_OK = True

git/cmd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ def execute(
965965
# Only search PATH, not CWD. This must be in the *caller* environment. The "1" can be any value.
966966
maybe_patch_caller_env = patch_env("NoDefaultCurrentDirectoryInExePath", "1")
967967
else:
968-
cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable
968+
cmd_not_found_exception = FileNotFoundError
969969
maybe_patch_caller_env = contextlib.nullcontext()
970970
# END handle
971971

git/compat.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55

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

8-
# flake8: noqa
9-
108
import locale
119
import os
1210
import sys
1311

14-
from gitdb.utils.encoding import (
15-
force_bytes, # @UnusedImport
16-
force_text, # @UnusedImport
17-
)
12+
from gitdb.utils.encoding import force_bytes, force_text # noqa: F401 # @UnusedImport
1813

1914
# typing --------------------------------------------------------------------
2015

21-
from typing import (
16+
from typing import ( # noqa: F401
2217
Any,
2318
AnyStr,
2419
Dict,

git/index/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33

44
"""Initialize the index package."""
55

6-
# flake8: noqa
7-
8-
from .base import *
9-
from .typ import *
6+
from .base import * # noqa: F401 F403
7+
from .typ import * # noqa: F401 F403

git/objects/__init__.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@
33

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

6-
# flake8: noqa
7-
86
import inspect
97

10-
from .base import *
11-
from .blob import *
12-
from .commit import *
8+
from .base import * # noqa: F403
9+
from .blob import * # noqa: F403
10+
from .commit import * # noqa: F403
1311
from .submodule import util as smutil
14-
from .submodule.base import *
15-
from .submodule.root import *
16-
from .tag import *
17-
from .tree import *
12+
from .submodule.base import * # noqa: F403
13+
from .submodule.root import * # noqa: F403
14+
from .tag import * # noqa: F403
15+
from .tree import * # noqa: F403
1816

1917
# Fix import dependency - add IndexObject to the util module, so that it can be
2018
# imported by the submodule.base.
21-
smutil.IndexObject = IndexObject # type: ignore[attr-defined]
22-
smutil.Object = Object # type: ignore[attr-defined]
19+
smutil.IndexObject = IndexObject # type: ignore[attr-defined] # noqa: F405
20+
smutil.Object = Object # type: ignore[attr-defined] # noqa: F405
2321
del smutil
2422

2523
# Must come after submodule was made available.

git/objects/submodule/base.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ def move(self, module_path: PathLike, configuration: bool = True, module: bool =
958958
raise
959959
# END handle undo rename
960960

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

@@ -976,19 +976,19 @@ def remove(
976976
from the .gitmodules file and the entry in the .git/config file.
977977
978978
:param module: If True, the checked out module we point to will be deleted as
979-
well.If that module is currently on a commit outside any branch in the
979+
well. If that module is currently on a commit outside any branch in the
980980
remote, or if it is ahead of its tracking branch, or if there are modified
981-
or untracked files in its working tree, then the removal will fail.
982-
In case the removal of the repository fails for these reasons, the
983-
submodule status will not have been altered.
981+
or untracked files in its working tree, then the removal will fail. In case
982+
the removal of the repository fails for these reasons, the submodule status
983+
will not have been altered.
984984
If this submodule has child modules of its own, these will be deleted prior
985985
to touching the direct submodule.
986986
:param force: Enforces the deletion of the module even though it contains
987987
modifications. This basically enforces a brute-force file system based
988988
deletion.
989989
:param configuration: If True, the submodule is deleted from the configuration,
990-
otherwise it isn't. Although this should be enabled most of the time,
991-
this flag enables you to safely delete the repository of your submodule.
990+
otherwise it isn't. Although this should be enabled most of the time, this
991+
flag enables you to safely delete the repository of your submodule.
992992
:param dry_run: If True, we will not actually do anything, but throw the errors
993993
we would usually throw.
994994
:return: self

git/objects/util.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,27 @@
55

66
"""General utility functions."""
77

8-
# flake8: noqa F401
9-
10-
118
from abc import ABC, abstractmethod
12-
import warnings
13-
from git.util import IterableList, IterableObj, Actor
14-
15-
import re
9+
import calendar
1610
from collections import deque
17-
11+
from datetime import datetime, timedelta, tzinfo
1812
from string import digits
13+
import re
1914
import time
20-
import calendar
21-
from datetime import datetime, timedelta, tzinfo
15+
import warnings
16+
17+
from git.util import IterableList, IterableObj, Actor
2218

2319
# typing ------------------------------------------------------------
2420
from typing import (
2521
Any,
2622
Callable,
2723
Deque,
2824
Iterator,
29-
Generic,
25+
# Generic,
3026
NamedTuple,
3127
overload,
32-
Sequence, # NOQA: F401
28+
Sequence,
3329
TYPE_CHECKING,
3430
Tuple,
3531
Type,
@@ -38,7 +34,7 @@
3834
cast,
3935
)
4036

41-
from git.types import Has_id_attribute, Literal, _T # NOQA: F401
37+
from git.types import Has_id_attribute, Literal # , _T
4238

4339
if TYPE_CHECKING:
4440
from io import BytesIO, StringIO

git/refs/__init__.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# This module is part of GitPython and is released under the
22
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
33

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

7-
from .symbolic import *
8-
from .reference import *
9-
from .head import *
10-
from .tag import *
11-
from .remote import *
6+
from .symbolic import * # noqa: F401 F403
7+
from .reference import * # noqa: F401 F403
8+
from .head import * # noqa: F401 F403
9+
from .tag import * # noqa: F401 F403
10+
from .remote import * # noqa: F401 F403
1211

13-
from .log import *
12+
from .log import * # noqa: F401 F403

git/refs/log.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
from git.types import PathLike
3232

3333
if TYPE_CHECKING:
34-
from git.refs import SymbolicReference
3534
from io import BytesIO
36-
from git.config import GitConfigParser, SectionConstraint # NOQA
35+
from git.refs import SymbolicReference
36+
from git.config import GitConfigParser, SectionConstraint
3737

3838
# ------------------------------------------------------------------------------
3939

git/refs/reference.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
# typing ------------------------------------------------------------------
1212

13-
from typing import Any, Callable, Iterator, Type, Union, TYPE_CHECKING # NOQA
14-
from git.types import Commit_ish, PathLike, _T # NOQA
13+
from typing import Any, Callable, Iterator, Type, Union, TYPE_CHECKING
14+
from git.types import Commit_ish, PathLike, _T
1515

1616
if TYPE_CHECKING:
1717
from git.repo import Repo

git/refs/symbolic.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# This module is part of GitPython and is released under the
22
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
33

4-
from git.types import PathLike
54
import os
65

76
from git.compat import defenc
@@ -31,8 +30,8 @@
3130
Union,
3231
TYPE_CHECKING,
3332
cast,
34-
) # NOQA
35-
from git.types import Commit_ish, PathLike # NOQA
33+
)
34+
from git.types import Commit_ish, PathLike
3635

3736
if TYPE_CHECKING:
3837
from git.repo import Repo

git/repo/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33

44
"""Initialize the Repo package."""
55

6-
# flake8: noqa
7-
8-
from .base import Repo as Repo
6+
from .base import Repo as Repo # noqa: F401

git/types.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# This module is part of GitPython and is released under the
22
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
33

4-
# flake8: noqa
5-
64
import os
75
import sys
8-
from typing import (
6+
from typing import ( # noqa: F401
97
Dict,
108
NoReturn,
119
Sequence as Sequence,
@@ -16,24 +14,24 @@
1614
Callable,
1715
TYPE_CHECKING,
1816
TypeVar,
19-
) # noqa: F401
17+
)
2018

2119
if sys.version_info >= (3, 8):
22-
from typing import (
20+
from typing import ( # noqa: F401
2321
Literal,
2422
TypedDict,
2523
Protocol,
2624
SupportsIndex as SupportsIndex,
2725
runtime_checkable,
28-
) # noqa: F401
26+
)
2927
else:
30-
from typing_extensions import (
28+
from typing_extensions import ( # noqa: F401
3129
Literal,
3230
SupportsIndex as SupportsIndex,
3331
TypedDict,
3432
Protocol,
3533
runtime_checkable,
36-
) # noqa: F401
34+
)
3735

3836
# if sys.version_info >= (3, 10):
3937
# from typing import TypeGuard # noqa: F401

git/util.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,9 @@
6262
Has_id_attribute,
6363
)
6464

65-
T_IterableObj = TypeVar("T_IterableObj", bound=Union["IterableObj", "Has_id_attribute"], covariant=True)
66-
# So IterableList[Head] is subtype of IterableList[IterableObj]
67-
6865
# ---------------------------------------------------------------------
6966

70-
from gitdb.util import ( # NOQA @IgnorePep8
67+
from gitdb.util import ( # noqa: F401 # @IgnorePep8
7168
make_sha,
7269
LockedFD, # @UnusedImport
7370
file_contents_ro, # @UnusedImport
@@ -79,6 +76,9 @@
7976
hex_to_bin, # @UnusedImport
8077
)
8178

79+
T_IterableObj = TypeVar("T_IterableObj", bound=Union["IterableObj", "Has_id_attribute"], covariant=True)
80+
# So IterableList[Head] is subtype of IterableList[IterableObj].
81+
8282
# NOTE: Some of the unused imports might be used/imported by others.
8383
# Handle once test-cases are back up and running.
8484
# Most of these are unused here, but are for use by git-python modules so these

test/lib/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# This module is part of GitPython and is released under the
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

6-
# flake8: noqa
76
import inspect
8-
from .helper import *
7+
8+
from .helper import * # noqa: F401 F403
99

1010
__all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]

test/lib/helper.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def repo_creator(self):
145145
os.chdir(rw_repo.working_dir)
146146
try:
147147
return func(self, rw_repo)
148-
except: # noqa E722
148+
except: # noqa: E722 B001
149149
log.info("Keeping repo after failure: %s", repo_dir)
150150
repo_dir = None
151151
raise
@@ -305,7 +305,7 @@ def remote_repo_creator(self):
305305
with cwd(rw_repo.working_dir):
306306
try:
307307
return func(self, rw_repo, rw_daemon_repo)
308-
except: # noqa E722
308+
except: # noqa: E722 B001
309309
log.info(
310310
"Keeping repos after failure: \n rw_repo_dir: %s \n rw_daemon_repo_dir: %s",
311311
rw_repo_dir,

test/test_commit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def test_datetimes(self):
475475
commit.authored_datetime,
476476
datetime(2009, 10, 8, 18, 17, 5, tzinfo=tzoffset(-7200)),
477477
commit.authored_datetime,
478-
) # noqa
478+
)
479479
self.assertEqual(
480480
commit.authored_datetime,
481481
datetime(2009, 10, 8, 16, 17, 5, tzinfo=utc),

0 commit comments

Comments
 (0)