|
6 | 6 | import ssl |
7 | 7 | import struct |
8 | 8 | import time |
9 | | -from types import FrameType |
10 | | -from typing import Any |
| 9 | +from types import FrameType, TracebackType |
| 10 | +from typing import Any, Self |
11 | 11 | from urllib.error import URLError |
12 | 12 | from urllib.parse import urlencode |
13 | 13 | from urllib.request import urlopen |
@@ -40,15 +40,15 @@ def raise_timeout(self, signl: int, frame: FrameType | None) -> None: |
40 | 40 | ''' |
41 | 41 | raise DownloadTimeout(f'Download timed out after {self.timeout} second(s).') |
42 | 42 |
|
43 | | - def __enter__(self): |
| 43 | + def __enter__(self) -> Self: |
44 | 44 | if self.timeout > 0: |
45 | 45 | self.previous_handler = signal.signal(signal.SIGALRM, self.raise_timeout) # type: ignore[assignment] |
46 | 46 | self.previous_timer = signal.alarm(self.timeout) |
47 | 47 |
|
48 | 48 | self.start_time = time.time() |
49 | 49 | return self |
50 | 50 |
|
51 | | - def __exit__(self, typ, value, traceback) -> None: |
| 51 | + def __exit__(self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None) -> None: |
52 | 52 | if self.start_time: |
53 | 53 | time_delta = time.time() - self.start_time |
54 | 54 | signal.alarm(0) |
@@ -164,7 +164,7 @@ def build_icmp(payload: bytes) -> bytes: |
164 | 164 | return struct.pack('!BBHHH', 8, 0, checksum, 0, 1) + payload |
165 | 165 |
|
166 | 166 |
|
167 | | -def ping(hostname, timeout=5) -> int: |
| 167 | +def ping(hostname, timeout: int = 5) -> int: |
168 | 168 | watchdog = select.epoll() |
169 | 169 | started = time.time() |
170 | 170 | random_identifier = f'archinstall-{random.randint(1000, 9999)}'.encode() |
|
0 commit comments