MCPcopy Index your code
hub / github.com/python/cpython / _isatty_open_only

Method _isatty_open_only

Lib/_pyio.py:1850–1863  ·  view source on GitHub ↗

Checks whether the file is a TTY using an open-only optimization. TTYs are always character devices. If the interpreter knows a file is not a character device when it would call ``isatty``, can skip that call. Inside ``open()`` there is a fresh stat result that contains tha

(self)

Source from the content-addressed store, hash-verified

1848 return os.isatty(self._fd)
1849
1850 def _isatty_open_only(self):
1851 """Checks whether the file is a TTY using an open-only optimization.
1852
1853 TTYs are always character devices. If the interpreter knows a file is
1854 not a character device when it would call ``isatty``, can skip that
1855 call. Inside ``open()`` there is a fresh stat result that contains that
1856 information. Use the stat result to skip a system call. Outside of that
1857 context TOCTOU issues (the fd could be arbitrarily modified by
1858 surrounding code).
1859 """
1860 if (self._stat_atopen is not None
1861 and not stat.S_ISCHR(self._stat_atopen.st_mode)):
1862 return False
1863 return os.isatty(self._fd)
1864
1865 @property
1866 def closefd(self):

Callers 1

openFunction · 0.95

Calls 1

isattyMethod · 0.45

Tested by

no test coverage detected