Hi!
There seems to be a mismatch between the type hint and the runtime check in Magika.identify_stream().
The signature accepts BinaryIO, which makes static checkers (like mypy/pyright) perfectly happy with standard unbuffered streams like io.FileIO. However, it crashes at runtime because of the strict isinstance(stream, io.BufferedIOBase) check.
Here is a minimal reproduction using only the standard library:
import io
from typing import BinaryIO
from magika import Magika
stream: BinaryIO = io.FileIO('any_file.txt', 'rb')
m = Magika()
# Crashes !!
m.identify_stream(stream)
Since the code already uses hasattr to check for seek, read, and tell right after the isinstance check, maybe the strict BufferedIOBase check could just be removed to fully support duck typing? Or if BufferedIOBase is strictly required, maybe update the type hint so static checkers can catch this early.
Hi!
There seems to be a mismatch between the type hint and the runtime check in Magika.identify_stream().
The signature accepts BinaryIO, which makes static checkers (like mypy/pyright) perfectly happy with standard unbuffered streams like io.FileIO. However, it crashes at runtime because of the strict isinstance(stream, io.BufferedIOBase) check.
Here is a minimal reproduction using only the standard library:
Since the code already uses hasattr to check for seek, read, and tell right after the isinstance check, maybe the strict BufferedIOBase check could just be removed to fully support duck typing? Or if BufferedIOBase is strictly required, maybe update the type hint so static checkers can catch this early.