Read the code carefully
from typing import Protocol, runtime_checkable
@runtime_checkable
class Closeable(Protocol):
def close(self) -> None: ...
class File:
def close(self):
return "file"
class Bag:
pass
class Stream:
"""Doesn't inherit Closeable; still passes by structural matching."""
def close(self):
return "stream"
class Weird:
"""Has a 'close' attribute, but it's an int."""
close = 42
print(isinstance(File(), Closeable))
print(isinstance(Bag(), Closeable))
print(isinstance(Stream(), Closeable))
print(isinstance(Weird(), Closeable))
What will the program print? Write here: