Skip to content

Commit

Permalink
test: Fix mypy types (shaka-project#169)
Browse files Browse the repository at this point in the history
On some versions, mypy thinks the file handle from the web server is BinaryIO, in others, BufferedIOBase.  We don't care which it is, as both have the methods we care about.

I tried the IOBase class from "io", but I get failures on certain devices.  This is the best solution I've found so far.
  • Loading branch information
joeyparrish authored Oct 30, 2024
1 parent 6b4b761 commit b087f05
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions streamer/proxy_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import urllib.parse

from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
from io import BufferedIOBase
from typing import Any, BinaryIO, Optional, Union

from streamer.node_base import ProcessStatus, ThreadedNodeBase
Expand Down Expand Up @@ -198,7 +199,7 @@ def do_DELETE(self) -> None:

@abc.abstractmethod
def handle_non_chunked(self, path: str, length: int,
file: BinaryIO) -> None:
file: Union[BinaryIO, BufferedIOBase]) -> None:
"""Write the non-chunked data stream from |file| to the destination."""
pass

Expand Down Expand Up @@ -236,7 +237,7 @@ def __init__(self, bucket: Any, base_path: str,
super().__init__(rate_limiter, *args, **kwargs)

def handle_non_chunked(self, path: str, length: int,
file: BinaryIO) -> None:
file: Union[BinaryIO, BufferedIOBase]) -> None:
# No leading slashes, or we get a blank folder name.
full_path = (self._base_path + path).strip('/')
blob = self._bucket.blob(full_path)
Expand Down Expand Up @@ -297,7 +298,7 @@ def __init__(self, client: Any, bucket_name: str, base_path: str,
super().__init__(rate_limiter, *args, **kwargs)

def handle_non_chunked(self, path: str, length: int,
file: BinaryIO) -> None:
file: Union[BinaryIO, BufferedIOBase]) -> None:
# No leading slashes, or we get a blank folder name.
full_path = (self._base_path + path).strip('/')
# length is unused here.
Expand Down

0 comments on commit b087f05

Please sign in to comment.