Skip to content

[Python] typing for bytes in typespec #5941

Closed

Description

@msyyc

According to https://typespec.io/docs/getting-started/typespec-for-openapi-dev/, openapi {"type": string; "format": binary} equals to typespec bytes

Image
However, python emitter emit the former to BinaryType whose typing is IO while the latter to ByteArraySchema whose typing is bytes.

Context

the issue is reported by catalinaperalta who is helping migrate loadtesting to typespec.

Activity

  1. msyyc commented on Feb 11, 2025

    @msyyc
    ContributorAuthor

    To keep backward compatibility for migration, maybe we could add overload BinaryType for ByteArraySchema.

  2. catalinaperalta commented on Feb 11, 2025

    @catalinaperalta
    Member

    Yuchao Yan (@msyyc) so in this case you suggest that the team patches the method in patch.py for python?

  3. msyyc commented on Feb 12, 2025

    @msyyc
    ContributorAuthor

    @msyyc so in this case you suggest that the team patches the method in patch.py for python?

    We are still in discussion and I update you with final decision after tomorrow. Thanks!

  4. msyyc commented on Feb 13, 2025

    @msyyc
    ContributorAuthor

    Update: catalinaperalta, python emitter will add overload with IO for it to keep compatibility and the SDK API will look like:

    @overlaod def op(body: IO, ...): ...
    
    @overload def op(body: bytes, ...): ...
    
    def op(body: Union[IO, bytes], ...): ...

    If python emitter can't catch up with service team's ETA, they could patch if for now.

  5. catalinaperalta commented on Feb 13, 2025

    @catalinaperalta
    Member

    Thanks for the update Yuchao Yan (@msyyc)! Do you have an ETA for when this will be checked in?

  6. msyyc commented on Feb 14, 2025

    @msyyc
    ContributorAuthor

    Since typespec is going to GA before end of March, language emitters including python emitter are busy in other necessary items for GA. So I am not sure about whether we have spare time to fix it for now. I will keep track and update for this issue.

  7. linked a pull request that will close this issue Fix Python typing for bytes in typespec #11233on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

emitter:client:pythonIssue for the Python client emitter: @typespec/http-client-python

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions