Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41d22b2

Browse files
committed
Overhaul noqa directives
- Remove some noqa directives that are not needed at all anymore. But there may still be some others I did not find.- Fix the code and remove the noqa direcive in places where the change is very simple and does not affect the interface (e.g., what could be taken to be public or not, what symbols are available and what they refer to, etc.), the change makes the code more idiomatic or clearer, and it fixes the flake8 complaint completely.- Turn file-level noqa directives into statement-level ones. A noqa directive at file level, even if it lists one or more specific error/warning numbers, actually suppresses flake8 for the entire file. So the main benefit here is to enable other warnings. But this also makes it clear what is producing the ones we suppress, which makes it easier to know what is intentional and how it may be reasonable to change it in the future.- Move noqa directives at the end of multi-line imports to the top line, where flake8 honors them, and eliminate redundant directives that were added to work around their ineffectiveness. (This is not really separate from the above point, since this is often what allowed file-level directives to be removed.)- Specify the errors/warnings each "noqa" should suppress. That is, this turns every bare "noqa", aside from those eliminated as described above, into a "noqa" for one or more specific errors/warnings. This makes the intent clearer and avoids oversuppression.- Add missing ":" between "noqa" and error/warning numbers. When these were absent, the intention was to suppress only the specifically listed errors/warnings, but the effect was that the listed numbers were ignored and *everything* was suppressed. In a couple of cases it was necessary to change the listed numbers to correct the list to what actually needed to be suppressed.- Write every "noqa" in lower-case (not "NOQA"). There did not appear to be a systematic reason for the different casing, and having them all cased the same makes it easier to avoid mistakes when grepping for them.- Where an import is unused and does not appear intended to be accesed from other modules, and is present only to support code in the same module that is commented out, but whose removal should be considered separately, comment out the statement or part of the statement that imports it as well, rather than writing a "noqa" for the unused import. This applies to only one file, git/objects/util.py.
1 parentcf5cb84 commit41d22b2

21 files changed

+75
-95
lines changed

‎git/__init__.py

Lines changed: 13 additions & 14 deletions
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-
fromgit.excimport*# @NoMove @IgnorePep8
10-
fromtypingimportList,Optional,Sequence,Tuple,Union,TYPE_CHECKING
11-
fromgit.typesimportPathLike
12-
138
__version__="git"
149

10+
fromtypingimportList,Optional,Sequence,Tuple,Union,TYPE_CHECKING
11+
1512
fromgitdb.utilimportto_hex_sha
13+
fromgit.excimport*# noqa: F403 # @NoMove @IgnorePep8
14+
fromgit.typesimportPathLike
1615

1716
try:
1817
fromgit.compatimportsafe_decode# @NoMove @IgnorePep8
1918
fromgit.configimportGitConfigParser# @NoMove @IgnorePep8
20-
fromgit.objectsimport*# @NoMove @IgnorePep8
21-
fromgit.refsimport*# @NoMove @IgnorePep8
22-
fromgit.diffimport*# @NoMove @IgnorePep8
23-
fromgit.dbimport*# @NoMove @IgnorePep8
19+
fromgit.objectsimport*#noqa: F403 #@NoMove @IgnorePep8
20+
fromgit.refsimport*#noqa: F403 #@NoMove @IgnorePep8
21+
fromgit.diffimport*#noqa: F403 #@NoMove @IgnorePep8
22+
fromgit.dbimport*#noqa: F403 #@NoMove @IgnorePep8
2423
fromgit.cmdimportGit# @NoMove @IgnorePep8
2524
fromgit.repoimportRepo# @NoMove @IgnorePep8
26-
fromgit.remoteimport*# @NoMove @IgnorePep8
27-
fromgit.indeximport*# @NoMove @IgnorePep8
25+
fromgit.remoteimport*#noqa: F403 #@NoMove @IgnorePep8
26+
fromgit.indeximport*#noqa: F403 #@NoMove @IgnorePep8
2827
fromgit.utilimport (# @NoMove @IgnorePep8
2928
LockFile,
3029
BlockingLockFile,
@@ -33,12 +32,12 @@
3332
remove_password_if_present,
3433
rmtree,
3534
)
36-
exceptGitErroras_exc:
35+
exceptGitErroras_exc:# noqa: F405
3736
raiseImportError("%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
ifnotGit.refresh(path=path):
129128
return
130-
ifnotFetchInfo.refresh():
129+
ifnotFetchInfo.refresh():# noqa: F405
131130
return# type: ignore [unreachable]
132131

133132
GIT_OK=True

‎git/cmd.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 7 deletions
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
importlocale
119
importos
1210
importsys
1311

14-
fromgitdb.utils.encodingimport (
15-
force_bytes,# @UnusedImport
16-
force_text,# @UnusedImport
17-
)
12+
fromgitdb.utils.encodingimportforce_bytes,force_text# noqa: F401 # @UnusedImport
1813

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

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

‎git/index/__init__.py

Lines changed: 2 additions & 4 deletions
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 .baseimport*
9-
from .typimport*
6+
from .baseimport*# noqa: F401 F403
7+
from .typimport*# noqa: F401 F403

‎git/objects/__init__.py

Lines changed: 9 additions & 11 deletions
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
importinspect
97

10-
from .baseimport*
11-
from .blobimport*
12-
from .commitimport*
8+
from .baseimport*# noqa: F403
9+
from .blobimport*# noqa: F403
10+
from .commitimport*# noqa: F403
1311
from .submoduleimportutilassmutil
14-
from .submodule.baseimport*
15-
from .submodule.rootimport*
16-
from .tagimport*
17-
from .treeimport*
12+
from .submodule.baseimport*# noqa: F403
13+
from .submodule.rootimport*# noqa: F403
14+
from .tagimport*# noqa: F403
15+
from .treeimport*# 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
delsmutil
2422

2523
# Must come after submodule was made available.

‎git/objects/util.py

Lines changed: 9 additions & 13 deletions
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
fromabcimportABC,abstractmethod
12-
importwarnings
13-
fromgit.utilimportIterableList,IterableObj,Actor
14-
15-
importre
9+
importcalendar
1610
fromcollectionsimportdeque
17-
11+
fromdatetimeimportdatetime,timedelta,tzinfo
1812
fromstringimportdigits
13+
importre
1914
importtime
20-
importcalendar
21-
fromdatetimeimportdatetime,timedelta,tzinfo
15+
importwarnings
16+
17+
fromgit.utilimportIterableList,IterableObj,Actor
2218

2319
# typing ------------------------------------------------------------
2420
fromtypingimport (
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-
fromgit.typesimportHas_id_attribute,Literal,_T# NOQA: F401
37+
fromgit.typesimportHas_id_attribute,Literal# , _T
4238

4339
ifTYPE_CHECKING:
4440
fromioimportBytesIO,StringIO

‎git/refs/__init__.py

Lines changed: 6 additions & 7 deletions
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 .symbolicimport*
8-
from .referenceimport*
9-
from .headimport*
10-
from .tagimport*
11-
from .remoteimport*
6+
from .symbolicimport*# noqa: F401 F403
7+
from .referenceimport*# noqa: F401 F403
8+
from .headimport*# noqa: F401 F403
9+
from .tagimport*# noqa: F401 F403
10+
from .remoteimport*# noqa: F401 F403
1211

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

‎git/refs/log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
fromgit.typesimportPathLike
3232

3333
ifTYPE_CHECKING:
34-
fromgit.refsimportSymbolicReference
3534
fromioimportBytesIO
36-
fromgit.configimportGitConfigParser,SectionConstraint# NOQA
35+
fromgit.refsimportSymbolicReference
36+
fromgit.configimportGitConfigParser,SectionConstraint
3737

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

‎git/refs/reference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

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

13-
fromtypingimportAny,Callable,Iterator,Type,Union,TYPE_CHECKING# NOQA
14-
fromgit.typesimportCommit_ish,PathLike,_T# NOQA
13+
fromtypingimportAny,Callable,Iterator,Type,Union,TYPE_CHECKING
14+
fromgit.typesimportCommit_ish,PathLike,_T
1515

1616
ifTYPE_CHECKING:
1717
fromgit.repoimportRepo

‎git/refs/symbolic.py

Lines changed: 2 additions & 3 deletions
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-
fromgit.typesimportPathLike
54
importos
65

76
fromgit.compatimportdefenc
@@ -31,8 +30,8 @@
3130
Union,
3231
TYPE_CHECKING,
3332
cast,
34-
)# NOQA
35-
fromgit.typesimportCommit_ish,PathLike# NOQA
33+
)
34+
fromgit.typesimportCommit_ish,PathLike
3635

3736
ifTYPE_CHECKING:
3837
fromgit.repoimportRepo

‎git/repo/__init__.py

Lines changed: 1 addition & 3 deletions
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 .baseimportRepoasRepo
6+
from .baseimportRepoasRepo# noqa: F401

‎git/types.py

Lines changed: 6 additions & 8 deletions
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
importos
75
importsys
8-
fromtypingimport (
6+
fromtypingimport (# noqa: F401
97
Dict,
108
NoReturn,
119
SequenceasSequence,
@@ -16,24 +14,24 @@
1614
Callable,
1715
TYPE_CHECKING,
1816
TypeVar,
19-
)# noqa: F401
17+
)
2018

2119
ifsys.version_info>= (3,8):
22-
fromtypingimport (
20+
fromtypingimport (# noqa: F401
2321
Literal,
2422
TypedDict,
2523
Protocol,
2624
SupportsIndexasSupportsIndex,
2725
runtime_checkable,
28-
)# noqa: F401
26+
)
2927
else:
30-
fromtyping_extensionsimport (
28+
fromtyping_extensionsimport (# noqa: F401
3129
Literal,
3230
SupportsIndexasSupportsIndex,
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

Lines changed: 4 additions & 4 deletions
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-
fromgitdb.utilimport (#NOQA @IgnorePep8
67+
fromgitdb.utilimport (#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

Lines changed: 2 additions & 2 deletions
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
importinspect
8-
from .helperimport*
7+
8+
from .helperimport*# noqa: F401 F403
99

1010
__all__= [nameforname,objinlocals().items()ifnot (name.startswith("_")orinspect.ismodule(obj))]

‎test/lib/helper.py

Lines changed: 2 additions & 2 deletions
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
returnfunc(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
withcwd(rw_repo.working_dir):
306306
try:
307307
returnfunc(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

Lines changed: 1 addition & 1 deletion
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),

‎test/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_multi_line_config(self):
125125
ev="ruby -e '\n"
126126
ev+="system %(git), %(merge-file), %(--marker-size=%L), %(%A), %(%O), %(%B)\n"
127127
ev+="b = File.read(%(%A))\n"
128-
ev+="b.sub!(/^<+ .*\\nActiveRecord::Schema\\.define.:version => (\\d+). do\\n=+\\nActiveRecord::Schema\\."# noqa E501
128+
ev+="b.sub!(/^<+ .*\\nActiveRecord::Schema\\.define.:version => (\\d+). do\\n=+\\nActiveRecord::Schema\\."# noqa: E501
129129
ev+="define.:version => (\\d+). do\\n>+ .*/) do\n"
130130
ev+=" %(ActiveRecord::Schema.define(:version => #{[$1, $2].max}) do)\n"
131131
ev+="end\n"

‎test/test_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def tearDown(self):
2525
#
2626
# @skipIf(HIDE_WINDOWS_KNOWN_ERRORS,
2727
# "FIXME: helper.wrapper fails with: PermissionError: [WinError 5] Access is denied: "
28-
# "'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\test_work_tree_unsupportedryfa60di\\master_repo\\.git\\objects\\pack\\pack-bc9e0787aef9f69e1591ef38ea0a6f566ec66fe3.idx") # noqa E501
28+
# "'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\test_work_tree_unsupportedryfa60di\\master_repo\\.git\\objects\\pack\\pack-bc9e0787aef9f69e1591ef38ea0a6f566ec66fe3.idx") # noqa: E501
2929
@with_rw_directory
3030
deftest_init_repo_object(self,rw_dir):
3131
# [1-test_init_repo_object]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp