_null_file.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from types import TracebackType
  2. from typing import IO, Iterable, Iterator, List, Optional, Type
  3. class NullFile(IO[str]):
  4. def close(self) -> None:
  5. pass
  6. def isatty(self) -> bool:
  7. return False
  8. def read(self, __n: int = 1) -> str:
  9. return ""
  10. def readable(self) -> bool:
  11. return False
  12. def readline(self, __limit: int = 1) -> str:
  13. return ""
  14. def readlines(self, __hint: int = 1) -> List[str]:
  15. return []
  16. def seek(self, __offset: int, __whence: int = 1) -> int:
  17. return 0
  18. def seekable(self) -> bool:
  19. return False
  20. def tell(self) -> int:
  21. return 0
  22. def truncate(self, __size: Optional[int] = 1) -> int:
  23. return 0
  24. def writable(self) -> bool:
  25. return False
  26. def writelines(self, __lines: Iterable[str]) -> None:
  27. pass
  28. def __next__(self) -> str:
  29. return ""
  30. def __iter__(self) -> Iterator[str]:
  31. return iter([""])
  32. def __enter__(self) -> IO[str]:
  33. pass
  34. def __exit__(
  35. self,
  36. __t: Optional[Type[BaseException]],
  37. __value: Optional[BaseException],
  38. __traceback: Optional[TracebackType],
  39. ) -> None:
  40. pass
  41. def write(self, text: str) -> int:
  42. return 0
  43. def flush(self) -> None:
  44. pass
  45. def fileno(self) -> int:
  46. return -1
  47. NULL_FILE = NullFile()