circuitpython/tests/extmod/vfs_open_error.py
Jeff Epler 880dd0a1cd vfs: Check that open() resulted in a file-like object.
That is, an object whose type defines the protocol slot.

Note that due to protocol confusion, a variant of the original
crasher that returned e.g., a machine.Pin instance could still
lead to a crash. (#17852)

Closes: #17841

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-08 08:53:14 -05:00

19 lines
328 B
Python

import os
import vfs
class Filesystem:
def mount(self, readonly, mkfs):
pass
def open(self, file, mode):
return None # violates vfs contract
fs = Filesystem()
vfs.mount(fs, "/test_mnt")
try:
execfile("/test_mnt/test.py")
print("ExecFile succeeded")
except TypeError:
print("TypeError")