Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.stat on windows doesn't take an open file even though os.stat in os.supports_fd #91354

Closed
snoopyjc mannequin opened this issue Apr 2, 2022 · 2 comments
Closed

os.stat on windows doesn't take an open file even though os.stat in os.supports_fd #91354

snoopyjc mannequin opened this issue Apr 2, 2022 · 2 comments
Labels
3.10 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@snoopyjc
Copy link
Mannequin

snoopyjc mannequin commented Apr 2, 2022

BPO 47198
Nosy @eryksun, @snoopyjc

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2022-04-02.04:31:08.895>
created_at = <Date 2022-04-02.03:51:52.564>
labels = ['type-bug', 'invalid', '3.10']
title = "os.stat on windows doesn't take an open file even though os.stat in os.supports_fd"
updated_at = <Date 2022-04-02.04:31:08.892>
user = 'https://github.com/snoopyjc'

bugs.python.org fields:

activity = <Date 2022-04-02.04:31:08.892>
actor = 'eryksun'
assignee = 'none'
closed = True
closed_date = <Date 2022-04-02.04:31:08.895>
closer = 'eryksun'
components = []
creation = <Date 2022-04-02.03:51:52.564>
creator = 'snoopyjc'
dependencies = []
files = []
hgrepos = []
issue_num = 47198
keywords = []
message_count = 2.0
messages = ['416535', '416536']
nosy_count = 2.0
nosy_names = ['eryksun', 'snoopyjc']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue47198'
versions = ['Python 3.10']

@snoopyjc
Copy link
Mannequin Author

snoopyjc mannequin commented Apr 2, 2022

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

@snoopyjc snoopyjc mannequin added 3.10 only security fixes type-bug An unexpected behavior, bug, or error labels Apr 2, 2022
@eryksun
Copy link
Contributor

eryksun commented Apr 2, 2022

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

@eryksun eryksun closed this as completed Apr 2, 2022
@eryksun eryksun added the invalid label Apr 2, 2022
@eryksun eryksun closed this as completed Apr 2, 2022
@eryksun eryksun added the invalid label Apr 2, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant