Python: 在不可寻址的流上,identify_stream() 会引发 UnboundLocalError,而不是真正的 OSError
作者: kaluli123123创建于 2026年9月14日更新于 2026年9月14日
Rust/src/magika/magika.py:203-209:
try:
current_position = stream.tell()
result = self._get_result_from_seekable(Seekable(stream))
finally:
# seek to the previous position even in case of exceptions
stream.seek(current_position)
return resultcurrent_position is bound inside the try block but referenced unconditionally in finally. When the first statement (stream.tell()) raises, the name was never bound, so finally raises UnboundLocalError and replaces the real exception.
内容来源: google/magika