fix(mypy): resolve union type and list annotation errors

- batches.py: Fix bytes/memoryview union type narrowing issue
- encoder_utils.py: Add type annotation for masks_list

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ashwin Bharambe 2025-10-27 23:04:59 -07:00
parent d612924f5b
commit a40af5b91b
2 changed files with 5 additions and 6 deletions

View file

@ -141,7 +141,7 @@ def build_encoder_attention_mask(
""" """
Build vision encoder attention mask that omits padding tokens. Build vision encoder attention mask that omits padding tokens.
""" """
masks_list = [] masks_list: list[torch.Tensor] = []
for arx in ar: for arx in ar:
mask_i = torch.ones((num_chunks, x.shape[2], 1), dtype=x.dtype) mask_i = torch.ones((num_chunks, x.shape[2], 1), dtype=x.dtype)
mask_i[: arx[0] * arx[1], :ntok] = 0 mask_i[: arx[0] * arx[1], :ntok] = 0

View file

@ -358,11 +358,10 @@ class ReferenceBatchesImpl(Batches):
# TODO(SECURITY): do something about large files # TODO(SECURITY): do something about large files
file_content_response = await self.files_api.openai_retrieve_file_content(batch.input_file_id) file_content_response = await self.files_api.openai_retrieve_file_content(batch.input_file_id)
# Handle both bytes and memoryview types # Handle both bytes and memoryview types - convert to bytes unconditionally
body = file_content_response.body # (bytes(x) returns x if already bytes, creates new bytes from memoryview otherwise)
if isinstance(body, memoryview): body_bytes = bytes(file_content_response.body)
body = bytes(body) file_content = body_bytes.decode("utf-8")
file_content = body.decode("utf-8")
for line_num, line in enumerate(file_content.strip().split("\n"), 1): for line_num, line in enumerate(file_content.strip().split("\n"), 1):
if line.strip(): # skip empty lines if line.strip(): # skip empty lines
try: try: