Skip to content

Commit

Permalink
Fix formatting, typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Nov 5, 2024
1 parent 77d0e0e commit ba2530e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
39 changes: 29 additions & 10 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,12 @@ def __init__(self, path_encoding=DEFAULT_ENCODING, **kwargs) -> None:
self._remote_path_encoding = path_encoding
super().__init__(**kwargs)

async def _connect(self, cmd, path, protocol_version: Optional[int] = None):
def _connect(
self,
cmd: bytes,
path: Union[str, bytes],
protocol_version: Optional[int] = None,
) -> tuple[Protocol, Callable[[], bool], Optional[IO[bytes]]]:
"""Create a connection to the server.
This method is abstract - concrete implementations should
Expand Down Expand Up @@ -1566,7 +1571,12 @@ def get_url(self, path):
netloc += ":%d" % self._port
return urlunsplit(("git", netloc, path, "", ""))

def _connect(self, cmd, path, protocol_version: Optional[int] = None):
def _connect(
self,
cmd: bytes,
path: Union[str, bytes],
protocol_version: Optional[int] = None,
) -> tuple[Protocol, Callable[[], bool], Optional[IO[bytes]]]:
if not isinstance(cmd, bytes):
raise TypeError(cmd)
if not isinstance(path, bytes):
Expand All @@ -1576,8 +1586,8 @@ def _connect(self, cmd, path, protocol_version: Optional[int] = None):
)
s = None
err = OSError(f"no address found for {self._host}")
for family, socktype, proto, canonname, sockaddr in sockaddrs:
s = socket.socket(family, socktype, proto)
for family, socktype, protof, canonname, sockaddr in sockaddrs:
s = socket.socket(family, socktype, protof)
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
try:
s.connect(sockaddr)
Expand Down Expand Up @@ -1686,7 +1696,12 @@ def from_parsedurl(cls, parsedurl, **kwargs):

git_command = None

def _connect(self, service, path, protocol_version: Optional[int] = None):
def _connect(
self,
service: bytes,
path: Union[bytes, str],
protocol_version: Optional[int] = None,
) -> tuple[Protocol, Callable[[], bool], Optional[IO[bytes]]]:
if not isinstance(service, bytes):
raise TypeError(service)
if isinstance(path, bytes):
Expand Down Expand Up @@ -2150,7 +2165,12 @@ def _get_cmd_path(self, cmd):
assert isinstance(cmd, bytes)
return cmd

def _connect(self, cmd, path, protocol_version: Optional[int] = None):
def _connect(
self,
cmd: bytes,
path: Union[str, bytes],
protocol_version: Optional[int] = None,
) -> tuple[Protocol, Callable[[], bool], Optional[IO[bytes]]]:
if not isinstance(cmd, bytes):
raise TypeError(cmd)
if isinstance(path, bytes):
Expand Down Expand Up @@ -2446,10 +2466,9 @@ def begin_protocol_v2(proto):
for prefix in ref_prefix:
pkts.append(b"ref-prefix " + prefix)

body = b"".join([
pkt_line(b"command=ls-refs\n"),
b"0001",
pkt_seq(*pkts)])
body = b"".join(
[pkt_line(b"command=ls-refs\n"), b"0001", pkt_seq(*pkts)]
)

resp, read = self._smart_request(
service.decode("ascii"), base_url, body
Expand Down
1 change: 0 additions & 1 deletion tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@


class PktLinetests:

def test_pkt_line(self):
self.assertEqual(b"0007bla", pkt_line(b"bla"))
self.assertEqual(b"0000", pkt_line(None))
Expand Down

0 comments on commit ba2530e

Please sign in to comment.