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

StrOrBytesPath | FileDescriptor alias #9297

Closed
Avasam opened this issue Nov 29, 2022 · 5 comments · Fixed by #9475
Closed

StrOrBytesPath | FileDescriptor alias #9297

Avasam opened this issue Nov 29, 2022 · 5 comments · Fixed by #9475

Comments

@Avasam
Copy link
Collaborator

Avasam commented Nov 29, 2022

Opening an issue so we don't forget.

Original comment from @AlexWaygood :

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.

@Avasam
Copy link
Collaborator Author

Avasam commented 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
Copy link
Member

AlexWaygood commented Jan 7, 2023

There don't seem to be any objections :)

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?

@JelleZijlstra
Copy link
Member

I would be okay with PathOrFD since "FD" for "file descriptor" is pretty commonly understood, but maybe it's still too obscure.

@hauntsaninja
Copy link
Collaborator

"fd" seems fine; it's commonly used as an identifier in the Python docs and e.g. os.fdopen is a thing

@AlexWaygood
Copy link
Member

I'd still lean towards FileDescriptorOrPath, but happy with either!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants