Skip to content

Commit d1c1f31

Browse files
authored
Merge pull request #1673 from EliahKagan/flake8
Upgrade and broaden flake8, fixing style problems and bugs
2 parents a5a6464 + c569320 commit d1c1f31

File tree

15 files changed

+64
-79
lines changed

15 files changed

+64
-79
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ignore = E265,E266,E731,E704,
2626
D,
2727
RST, RST3
2828

29-
exclude = .tox,.venv,build,dist,doc,git/ext/,test
29+
exclude = .tox,.venv,build,dist,doc,git/ext/
3030

3131
rst-roles = # for flake8-RST-docstrings
3232
attr,class,func,meth,mod,obj,ref,term,var # used by sphinx

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
repos:
22
- repo: https://github.com/PyCQA/flake8
3-
rev: 6.0.0
3+
rev: 6.1.0
44
hooks:
55
- id: flake8
66
additional_dependencies:
77
[
8-
flake8-bugbear==22.12.6,
9-
flake8-comprehensions==3.10.1,
8+
flake8-bugbear==23.9.16,
9+
flake8-comprehensions==3.14.0,
1010
flake8-typing-imports==1.14.0,
1111
]
12-
exclude: ^doc|^git/ext/|^test/
12+
exclude: ^doc|^git/ext/
1313

1414
- repo: https://github.com/pre-commit/pre-commit-hooks
1515
rev: v4.4.0

git/objects/submodule/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ def iter_items(
14031403
# END handle critical error
14041404

14051405
# Make sure we are looking at a submodule object
1406-
if type(sm) != git.objects.submodule.base.Submodule:
1406+
if type(sm) is not git.objects.submodule.base.Submodule:
14071407
continue
14081408

14091409
# fill in remaining info - saves time as it doesn't have to be parsed again

git/refs/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def entry_at(cls, filepath: PathLike, index: int) -> "RefLogEntry":
244244
for i in range(index + 1):
245245
line = fp.readline()
246246
if not line:
247-
raise IndexError(f"Index file ended at line {i+1}, before given index was reached")
247+
raise IndexError(f"Index file ended at line {i + 1}, before given index was reached")
248248
# END abort on eof
249249
# END handle runup
250250

git/repo/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ def __init__(
206206
if expand_vars and re.search(self.re_envvars, epath):
207207
warnings.warn(
208208
"The use of environment variables in paths is deprecated"
209-
+ "\nfor security reasons and may be removed in the future!!"
209+
+ "\nfor security reasons and may be removed in the future!!",
210+
stacklevel=1,
210211
)
211212
epath = expand_path(epath, expand_vars)
212213
if epath is not None:

git/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ class IterableClassWatcher(type):
11361136

11371137
def __init__(cls, name: str, bases: Tuple, clsdict: Dict) -> None:
11381138
for base in bases:
1139-
if type(base) == IterableClassWatcher:
1139+
if type(base) is IterableClassWatcher:
11401140
warnings.warn(
11411141
f"GitPython Iterable subclassed by {name}. "
11421142
"Iterable is deprecated due to naming clash since v3.1.18"

test/lib/helper.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,16 @@ def wrapper(self):
9494
os.mkdir(path)
9595
keep = False
9696
try:
97-
try:
98-
return func(self, path)
99-
except Exception:
100-
log.info(
101-
"Test %s.%s failed, output is at %r\n",
102-
type(self).__name__,
103-
func.__name__,
104-
path,
105-
)
106-
keep = True
107-
raise
97+
return func(self, path)
98+
except Exception:
99+
log.info(
100+
"Test %s.%s failed, output is at %r\n",
101+
type(self).__name__,
102+
func.__name__,
103+
path,
104+
)
105+
keep = True
106+
raise
108107
finally:
109108
# Need to collect here to be sure all handles have been closed. It appears
110109
# a windows-only issue. In fact things should be deleted, as well as
@@ -147,12 +146,11 @@ def repo_creator(self):
147146
prev_cwd = os.getcwd()
148147
os.chdir(rw_repo.working_dir)
149148
try:
150-
try:
151-
return func(self, rw_repo)
152-
except: # noqa E722
153-
log.info("Keeping repo after failure: %s", repo_dir)
154-
repo_dir = None
155-
raise
149+
return func(self, rw_repo)
150+
except: # noqa E722
151+
log.info("Keeping repo after failure: %s", repo_dir)
152+
repo_dir = None
153+
raise
156154
finally:
157155
os.chdir(prev_cwd)
158156
rw_repo.git.clear_cache()

test/test_commit.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def __init__(self, *args, **kwargs):
277277
super(Child, self).__init__(*args, **kwargs)
278278

279279
child_commits = list(Child.iter_items(self.rorepo, "master", paths=("CHANGES", "AUTHORS")))
280-
assert type(child_commits[0]) == Child
280+
assert type(child_commits[0]) is Child
281281

282282
def test_iter_items(self):
283283
# pretty not allowed
@@ -525,12 +525,12 @@ def test_trailers(self):
525525

526526
# check that trailer stays empty for multiple msg combinations
527527
msgs = [
528-
f"Subject\n",
529-
f"Subject\n\nBody with some\nText\n",
530-
f"Subject\n\nBody with\nText\n\nContinuation but\n doesn't contain colon\n",
531-
f"Subject\n\nBody with\nText\n\nContinuation but\n only contains one :\n",
532-
f"Subject\n\nBody with\nText\n\nKey: Value\nLine without colon\n",
533-
f"Subject\n\nBody with\nText\n\nLine without colon\nKey: Value\n",
528+
"Subject\n",
529+
"Subject\n\nBody with some\nText\n",
530+
"Subject\n\nBody with\nText\n\nContinuation but\n doesn't contain colon\n",
531+
"Subject\n\nBody with\nText\n\nContinuation but\n only contains one :\n",
532+
"Subject\n\nBody with\nText\n\nKey: Value\nLine without colon\n",
533+
"Subject\n\nBody with\nText\n\nLine without colon\nKey: Value\n",
534534
]
535535

536536
for msg in msgs:

test/test_diff.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import ddt
88
import shutil
99
import tempfile
10-
import unittest
1110
from git import (
1211
Repo,
1312
GitCommandError,

test/test_docs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ def test_references_and_objects(self, rw_dir):
263263
# [8-test_references_and_objects]
264264
hc = repo.head.commit
265265
hct = hc.tree
266-
hc != hct # @NoEffect
267-
hc != repo.tags[0] # @NoEffect
268-
hc == repo.head.reference.commit # @NoEffect
266+
hc != hct # noqa: B015 # @NoEffect
267+
hc != repo.tags[0] # noqa: B015 # @NoEffect
268+
hc == repo.head.reference.commit # noqa: B015 # @NoEffect
269269
# ![8-test_references_and_objects]
270270

271271
# [9-test_references_and_objects]
@@ -369,7 +369,7 @@ def test_references_and_objects(self, rw_dir):
369369
# The index contains all blobs in a flat list
370370
assert len(list(index.iter_blobs())) == len([o for o in repo.head.commit.tree.traverse() if o.type == "blob"])
371371
# Access blob objects
372-
for (_path, _stage), entry in index.entries.items():
372+
for (_path, _stage), _entry in index.entries.items():
373373
pass
374374
new_file_path = os.path.join(repo.working_tree_dir, "new-file-name")
375375
open(new_file_path, "w").close()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy