Skip to content

feat: use less restrictive io type for file ingest #168

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

Closed
wants to merge 1 commit into from

Conversation

alkasm
Copy link
Contributor

@alkasm alkasm commented Dec 12, 2024

Request's data param has type _Data | None as annotated, where _Data is defined as a union including SupportsRead[str | bytes] from typeshed. Since we don't need to parameterize by the string type (we already require binary file), I just copied over the impl from

class SupportsRead(Protocol[_T_co]):
    def read(self, length: int = ..., /) -> _T_co: ...

to

class HasBinaryRead(Protocol):
    def read(self, length: int = ..., /) -> bytes: ...

(and renamed to be in line with our other protocols)

@alkasm alkasm changed the title feat: use less restrictive type for file ingest feat: use less restrictive io type for file ingest Dec 12, 2024
Copy link
Contributor

@mariobuikhuizen mariobuikhuizen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the docstrings also be updated to reflect the new type?

@alkasm
Copy link
Contributor Author

alkasm commented Dec 16, 2024

Shouldn't the docstrings also be updated to reflect the new type?

the docstrings just give an example of a binary file-like object, so I think it's fine

@drake-nominal
Copy link
Contributor

Should we put this in a publicly-importable file? seems like something I could see users wanting to use in their types for code that interacts with nominal

@alkasm
Copy link
Contributor Author

alkasm commented Dec 17, 2024

Should we put this in a publicly-importable file? seems like something I could see users wanting to use in their types for code that interacts with nominal

hmm. This is the double edged sword. If I ask for something more specific (e.g. BinaryIO), it's more restrictive than it really needs to be for consumers. On the other hand, if I minimize it down to the tiniest necessary bit (just read()) and then suddenly need one new method (e.g. seek()) it's now a breaking change. Blah, why is IO so annoying in python.

@varun-nominal
Copy link
Contributor

this one still relevant?

@alkasm
Copy link
Contributor Author

alkasm commented Mar 3, 2025

nah lets just leave it as-is

@alkasm alkasm closed this Mar 3, 2025
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 this pull request may close these issues.

4 participants