Skip to content

Different return types for S3Path.stat() and WindowsUPath.stat() #145

@theogaraj

Description

@theogaraj

Which operating system and Python version are you using?
Windows 11, Python 3.9.6

Which version of this project are you using?
0.1.3

What did you do?
I am attempting to use universal_pathlib in order to have a unified way of handling files whether they are local or in S3.
One of the things I need to do is get all the files in a folder (yes I know S3 doesn't have actual folders, but hopefully you understand what I mean) and get their sizes.

>>> from upath import UPath
>>> lpath = UPath('local_data/files/')
>>>spath = UPath('s3://test_bucket/files/')
>>> lfiles = lpath.iterdir()
>>> lf = next(lfiles)
>>> type(lf.stat())
<class 'os.stat_result'>
>>> sfiles = spath.iterdir()
>>> sf = next(sfiles)
>>> type(sf.stat())
<class 'dict'>
>>> lf.stat().st_size
1657
>>> sf.stat().st_size
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'st_size'

What did you expect to see?
I expected to be able to use same code to get file sizes whether they are in local directory or in S3

What did you see instead?
The return types of stat() are different for S3Path vs WindowsUPath and I can't get file size in the same way from each.

Would this difference in behavior be something you would consider reconciling? Alternatively, do you have suggestions on another approach to achieving what I'm trying to do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't workingcompatibility 🤝Compatibility with stdlib pathlib

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions