Skip to content

StrOrBytesPath | FileDescriptor alias #9297

Closed

Description

@Avasam

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.

Activity

  1. Avasam commented on Jan 6, 2023

    @Avasam
    SponsorCollaboratorAuthor

    With a new mypy release around the corner, adding helper types before mypy updates its vendored typeshed might be a good idea.

  2. AlexWaygood commented on Jan 7, 2023

    @AlexWaygood
    Member

    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?

  3. JelleZijlstra commented on Jan 7, 2023

    @JelleZijlstra
    Member

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

  4. hauntsaninja commented on Jan 7, 2023

    @hauntsaninja
    Collaborator

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

  5. AlexWaygood commented on Jan 7, 2023

    @AlexWaygood
    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

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