Skip to content

Reconsider platform availability of stat.FILE_ATTRIBUTE_* #14865

@Ravencentric

Description

@Ravencentric

MRE

# a.py
import stat
import sys
from typing import reveal_type

assert sys.platform == "linux"
reveal_type(stat.FILE_ATTRIBUTE_READONLY)
$ mypy --strict a.py 
a.py:6:13: error: Module has no attribute "FILE_ATTRIBUTE_READONLY"  [attr-defined]
a.py:6:13: note: Revealed type is "Any"
Found 1 error in 1 file (checked 1 source file)
$ python a.py
Runtime type is 'int'

But why?

While searching for this, I did find some related threads:

So it is clearly intentional, but I would like typeshed to reconsider this and make FILE_ATTRIBUTE_* available on all platforms to match the runtime behavior. I encountered this while working on py7zr, which uses stat.FILE_ATTRIBUTE_* extensively on all platforms (if you want to know why, see here). Consequently, it ends up as Any, and we lose both type checking and auto-complete.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions