Skip to content

Commit

Permalink
Run pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Sep 29, 2023
1 parent 5dd4787 commit 0a5c62b
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 46 deletions.
8 changes: 2 additions & 6 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,8 @@ def find_git_command() -> List[str]:
"""Find command to run for system Git (usually C Git)."""
if sys.platform == "win32": # support .exe, .bat and .cmd
try: # to avoid overhead
import win32api
import pywintypes
import win32api
except ImportError: # run through cmd.exe with some overhead
return ["cmd", "/c", "git"]
else:
Expand Down Expand Up @@ -2181,11 +2181,7 @@ def from_parsedurl(cls, parsedurl, **kwargs):
return cls(urlunparse(parsedurl), **kwargs)

def __repr__(self) -> str:
return "{}({!r}, dumb={!r})".format(
type(self).__name__,
self._base_url,
self.dumb,
)
return f"{type(self).__name__}({self._base_url!r}, dumb={self.dumb!r})"


class Urllib3HttpGitClient(AbstractHttpGitClient):
Expand Down
3 changes: 1 addition & 2 deletions dulwich/cloud/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def __init__(self, bucket, subpath='') -> None:
self.subpath = subpath

def __repr__(self) -> str:
return "{}({!r}, subpath={!r})".format(
type(self).__name__, self.bucket, self.subpath)
return f"{type(self).__name__}({self.bucket!r}, subpath={self.subpath!r})"

def _remove_pack(self, name):
self.bucket.delete_blobs([
Expand Down
8 changes: 4 additions & 4 deletions dulwich/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

"""Implementation of merge-base following the approach of git."""

from .lru_cache import LRUCache
from heapq import heappop, heappush

from heapq import heappush, heappop
from .lru_cache import LRUCache


# priority queue using builtin python minheap tools
# why they do not have a builtin maxheap is simply ridiculous but
# liveable with integer time stamps using negation
class WorkList(object):
class WorkList:
def __init__(self):
self.pq = []

Expand Down Expand Up @@ -108,7 +108,7 @@ def _has_candidates(wlst, cstates):
# remove any duplicates and sort it so that earliest is first
results = []
for dt, cmt in cands:
if not ((cstates[cmt] & _DNC) == _DNC) and not (dt, cmt) in results:
if not ((cstates[cmt] & _DNC) == _DNC) and (dt, cmt) not in results:
results.append((dt, cmt))
results.sort(key=lambda x: x[0])
lcas = [cmt for dt, cmt in results]
Expand Down
6 changes: 1 addition & 5 deletions dulwich/ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ def __eq__(self, other: object) -> bool:
)

def __repr__(self) -> str:
return "{}({!r}, {!r})".format(
type(self).__name__,
self.pattern,
self.ignorecase,
)
return f"{type(self).__name__}({self.pattern!r}, {self.ignorecase!r})"

def match(self, path: bytes) -> bool:
"""Try to match a path against this ignore pattern.
Expand Down
10 changes: 5 additions & 5 deletions dulwich/lru_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,31 @@ def _walk_lru(self) -> Iterator[_LRUNode[K, V]]:
raise AssertionError(
"the _most_recently_used entry is not"
" supposed to have a previous entry"
" {}".format(node)
f" {node}"
)
while node is not None:
if node.next_key is _null_key:
if node is not self._least_recently_used:
raise AssertionError(
"only the last node should have" " no next value: {}".format(node)
"only the last node should have" f" no next value: {node}"
)
node_next = None
else:
node_next = self._cache[node.next_key]
if node_next.prev is not node:
raise AssertionError(
"inconsistency found, node.next.prev" " != node: {}".format(node)
"inconsistency found, node.next.prev" f" != node: {node}"
)
if node.prev is None:
if node is not self._most_recently_used:
raise AssertionError(
"only the _most_recently_used should"
" not have a previous node: {}".format(node)
f" not have a previous node: {node}"
)
else:
if node.prev.next_key != node.key:
raise AssertionError(
"inconsistency found, node.prev.next" " != node: {}".format(node)
"inconsistency found, node.prev.next" f" != node: {node}"
)
yield node
node = node_next
Expand Down
8 changes: 2 additions & 6 deletions dulwich/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,8 @@ def unified_diff(
started = True
fromdate = f"\t{fromfiledate}" if fromfiledate else ""
todate = f"\t{tofiledate}" if tofiledate else ""
yield "--- {}{}{}".format(
fromfile.decode(tree_encoding), fromdate, lineterm
).encode(output_encoding)
yield "+++ {}{}{}".format(
tofile.decode(tree_encoding), todate, lineterm
).encode(output_encoding)
yield f"--- {fromfile.decode(tree_encoding)}{fromdate}{lineterm}".encode(output_encoding)
yield f"+++ {tofile.decode(tree_encoding)}{todate}{lineterm}".encode(output_encoding)

first, last = group[0], group[-1]
file1_range = _format_range_unified(first[1], last[2])
Expand Down
4 changes: 1 addition & 3 deletions dulwich/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,9 +1037,7 @@ def test_from_parsedurl_on_url_with_quoted_credentials(self):
original_password = "Ya#1$2%3"
quoted_password = urlquote(original_password)

url = "https://{username}:{password}@github.com/jelmer/dulwich".format(
username=quoted_username, password=quoted_password
)
url = f"https://{quoted_username}:{quoted_password}@github.com/jelmer/dulwich"

c = HttpGitClient.from_parsedurl(urlparse(url))
self.assertEqual(original_username, c._username)
Expand Down
2 changes: 1 addition & 1 deletion dulwich/tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from dulwich.tests import TestCase

from ..graph import _find_lcas, can_fast_forward, WorkList
from ..graph import WorkList, _find_lcas, can_fast_forward
from ..repo import MemoryRepo
from .utils import make_commit

Expand Down
5 changes: 1 addition & 4 deletions dulwich/tests/test_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ def __init__(self, commit, changes) -> None:
self.changes = changes

def __repr__(self) -> str:
return "<TestWalkEntry commit={}, changes={!r}>".format(
self.commit.id,
self.changes,
)
return f"<TestWalkEntry commit={self.commit.id}, changes={self.changes!r}>"

def __eq__(self, other):
if not isinstance(other, WalkEntry) or self.commit != other.commit:
Expand Down
5 changes: 1 addition & 4 deletions dulwich/walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ def changes(self, path_prefix=None):
return self._changes[path_prefix]

def __repr__(self) -> str:
return "<WalkEntry commit={}, changes={!r}>".format(
self.commit.id,
self.changes(),
)
return f"<WalkEntry commit={self.commit.id}, changes={self.changes()!r}>"


class _CommitTimeQueue:
Expand Down
6 changes: 0 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@

from setuptools import Extension, setup

if sys.version_info < (3, 7):
raise Exception(
'Dulwich only supports Python 3.6 and later. '
'For 2.7 support, please install a version prior to 0.20')


if sys.platform == 'darwin' and os.path.exists('/usr/bin/xcodebuild'):
# XCode 4.0 dropped support for ppc architecture, which is hardcoded in
# distutils.sysconfig
Expand Down

0 comments on commit 0a5c62b

Please sign in to comment.