def isatty(stream):
    """Check if a stream is a tty.

    Not all file-like objects implement the `isatty` method.
    """
    fn = getattr(stream, 'isatty', None)
    if fn is None:
        return False
    return fn()