-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
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:
- Add Windows FILE_ATTRIBUTE constants available in
stat
but not in_stat
#12729 - move stat.FILE_ATTRIBUTE_* to _stat.pyi and fix availability #6761 (comment)
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
Labels
No labels