Verified Commit af9c54d6 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Improve typing of DownloadableBinaries abstract methods

parent 25e7a001
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ from pathlib import Path
from shutil import copyfileobj
from tarfile import TarFile
from typing import IO
from typing import TYPE_CHECKING

import requests
from packaging.version import Version
@@ -28,6 +29,9 @@ from xdg_base_dirs import xdg_cache_home
from behave_utils.json import JSONObject
from behave_utils.url import URL

if TYPE_CHECKING:
	from .types import Readable

CACHE_DIR: Path = xdg_cache_home() / "behave-testing"


@@ -92,7 +96,7 @@ class DownloadableExecutable(ABC):
		raise NotImplementedError

	@abstractmethod
	def get_stream(self, session: requests.Session, version: str) -> IO[bytes]:
	def get_stream(self, session: requests.Session, version: str) -> Readable[bytes]:
		"""
		Return a stream that emits the requested version of a supported binary

behave_utils/types.pyi

0 → 100644
+22 −0
Original line number Diff line number Diff line
#  Copyright 2024  Dominik Sekotill <dom.sekotill@kodo.org.uk>
#
#  This Source Code Form is subject to the terms of the Mozilla Public
#  License, v. 2.0. If a copy of the MPL was not distributed with this
#  file, You can obtain one at http://mozilla.org/MPL/2.0/.

"""
General type definitions
"""

from typing import Protocol
from typing import TypeVar

S_co = TypeVar("S_co", bound=str|bytes, covariant=True)


class Readable(Protocol[S_co]):
	"""
	Protocol for types that implement the read() method of file-like objects
	"""

	def read(self, _s: int = ..., /) -> S_co: ...