This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.stat on windows doesn't take an open file even though os.stat in os.supports_fd
Type: behavior Stage: resolved
Components: Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, snoopyjc
Priority: normal Keywords:

Created on 2022-04-02 03:51 by snoopyjc, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg416535 - (view) Author: Joe Cool (snoopyjc) Date: 2022-04-02 03:51
os.stat on windows doesn't take an open file even though os.stat in os.supports_fd

>>> fd = open('tmp.tmp', 'w')
>>> fd
<_io.TextIOWrapper name='tmp.tmp' mode='w' encoding='cp1252'>
>>> os.stat(fd)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: stat: path should be string, bytes, os.PathLike or integer, not TextIOWrapper
>>> os.stat in os.supports_fd
True
msg416536 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2022-04-02 04:31
You're mistaken about what `fd` is. It's a TextIOWrapper, which wraps a BufferedWriter, which buffers a FileIO raw file object, which accesses the open file number fd.fileno(). For example:

    >>> f = open('tmp.tmp','w')
    >>> os.stat(f.fileno()).st_size
    0
History
Date User Action Args
2022-04-11 14:59:58adminsetgithub: 91354
2022-04-02 04:31:08eryksunsetstatus: open -> closed

nosy: + eryksun
messages: + msg416536

resolution: not a bug
stage: resolved
2022-04-02 03:51:52snoopyjccreate