You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We could actually consider adding this alias to _typeshed; there's a bunch of functions in os/__init__.pyi that could use it. os/__init__.pyi currently defines an _FdOrAnyPath alias. We don't need to add the alias to _typeshed in this PR, though.
There's a handful of _OpenFile aliases also defined in multiple stubs
There's also a lot of int | StrOrBytesPath, StrOrBytesPath | int and StrOrBytesPath | FileDescriptor which could be replaced by the alias.
The only reservation I have is about the name. OpenFile isn't very descriptive/accurate, since for the StrOrBytesPath half of the alias, the file hasn't actually been opened yet. Maybe something like FileDescriptorOrPath?
Activity
Avasam commentedon Jan 6, 2023
With a new mypy release around the corner, adding helper types before mypy updates its vendored typeshed might be a good idea.
AlexWaygood commentedon Jan 7, 2023
There don't seem to be any objections :)
The only reservation I have is about the name.
OpenFileisn't very descriptive/accurate, since for theStrOrBytesPathhalf of the alias, the file hasn't actually been opened yet. Maybe something likeFileDescriptorOrPath?JelleZijlstra commentedon Jan 7, 2023
I would be okay with
PathOrFDsince "FD" for "file descriptor" is pretty commonly understood, but maybe it's still too obscure.hauntsaninja commentedon Jan 7, 2023
"fd" seems fine; it's commonly used as an identifier in the Python docs and e.g.
os.fdopenis a thingAlexWaygood commentedon Jan 7, 2023
I'd still lean towards
FileDescriptorOrPath, but happy with either!