Skip to content

Generate usable Python multipart file samples - #52

Merged
glenn-jocher merged 10 commits into
mainfrom
agents-md
Sep 11, 2026
Merged

Generate usable Python multipart file samples#52
glenn-jocher merged 10 commits into
mainfrom
agents-md

Conversation

@glenn-jocher

@glenn-jocher glenn-jocher commented Sep 11, 2026

Copy link
Copy Markdown
Member

Python multipart examples now open binary files instead of passing a literal path string. Match the generator transport's field classification and retain coverage in the existing generator test. Trim AGENTS.md to reusable product boundaries, commands, owner pointers, and pitfalls.

Validation: 20 tests passed (292 assertions), typecheck, lint, and knip passed.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Updated Python multipart code samples to open binary files instead of passing file paths as strings, while refining repository guidance and preserving generator coverage.

📊 Key Changes

  • Multipart file fields now generate open("path/to/file", "rb") expressions.
  • File detection follows the generator’s existing binary-field classification for both individual body arguments and multipart object properties.
  • Added a generator test assertion covering the binary file sample output.
  • Simplified AGENTS.md by consolidating commands, validation requirements, project boundaries, pointers, and Python output conventions.
  • Validation passed: 20 tests with 292 assertions, typecheck, lint, and knip.

🎯 Purpose & Impact

  • Generated Python samples for multipart/form-data requests now provide file handles suitable for the SDK’s multipart transport instead of literal path strings.
  • Non-multipart Python samples retain their existing value-generation behavior.

@UltralyticsAssistant UltralyticsAssistant added the documentation Improvements or additions to documentation label Sep 11, 2026
@UltralyticsAssistant

Copy link
Copy Markdown
Member

👋 Hello @glenn-jocher, thank you for submitting a ultralytics/openapi 🚀 PR! This automated message confirms your contribution was received, and an Ultralytics engineer will assist with the review. To ensure a seamless integration of your work, please review the following checklist:

  • Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • Synchronize with Source: Confirm your PR is synchronized with the ultralytics/openapi main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • Update Documentation: Update the relevant documentation for any new or modified features.
  • Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
  • Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

@UltralyticsAssistant UltralyticsAssistant added the enhancement New feature or request label Sep 11, 2026

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Reviewed the AGENTS.md additions against the repository’s package scripts, configuration loader, generator, shared OpenAPI helpers, workflows, and tests. The change is documentation-only and does not alter runtime behavior, but two factual descriptions should be corrected: the generated-package import check and the conditions that prevent request-body flattening.

💬 Posted 2 inline comments
  • 📝 LOW AGENTS.md:47 This describes the CI import shape incorrectly. CI imports the configured package (c["package"]) and checks the client and Async + client attributes; it does not import a module named <python.package>.<python.client>. Please make the command comment match .github/workflows/ci.yml so agents do not try an invalid module import.
  • 📝 LOW AGENTS.md:107 The additionalProperties exception is broader than the implementation. sdkArguments still flattens a plain object body with its own object-valued additionalProperties; the whole-body fallback only detects object-valued additionalProperties on allOf branches (along with the other listed constraints). Please scope this description to the actual behavior.

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review 2

Made with ❤️ by Ultralytics Actions

Since the previous review, both AGENTS.md findings are addressed: the CI import description and body-flattening exception now match the implementation. This revision also adds multipart-aware Python samples and coverage. One medium-risk edge case remains: recursive binary detection in samples is broader than the generated client's multipart file handling, so copied samples can be incorrect for union-valued binary fields.

💬 Posted 1 inline comment
  • 💡 MEDIUM lib/openapi.ts:569 This recursively classifies a multipart property as a file when any union branch has format: "binary", but the Python generator only puts properties with a direct resolved format: "binary" into files (methodSource and multipartBinary). For a schema such as file: { anyOf: [{ type: "string", format: "binary" }, { type: "null" }] }, the sample emits open("path/to/file", "rb") while the generated client passes that value through _form_data instead of uploading it as a file. Align th…

@glenn-jocher glenn-jocher changed the title Expand AGENTS.md with verified architecture, commands, and consumer contract Generate usable Python multipart file samples Sep 11, 2026

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review 3

Made with ❤️ by Ultralytics Actions

Since review 2, the multipart sample logic now checks direct resolved binary formats, addressing the prior union mismatch. One documentation regression remains: the current diff deletes the existing Architecture and Python Output guidance instead of preserving it as claimed. No other concrete runtime issues found.

💬 Posted 1 inline comment
  • 📝 LOW AGENTS.md:39 This replacement removes the existing Architecture and Python Output sections, despite the PR description saying those sections are preserved. Agents now lose the documented contract ownership, generated-output rules, API-key handling, client shape, async-client, docstring, and license guidance. Retain those sections while adding the new commands and validation guidance.

Comment thread AGENTS.md
Comment thread AGENTS.md

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review 4

Made with ❤️ by Ultralytics Actions

Since the previous review, the multipart sample logic now matches the Python generator’s direct binary-field classification, and the documentation scope change is settled by the maintainer. The test coverage exercises the generated open(..., "rb") sample. No new concrete runtime, compatibility, security, or maintainability issues found. LGTM.

@glenn-jocher
glenn-jocher merged commit 64ed08d into main Sep 11, 2026
5 checks passed
@glenn-jocher
glenn-jocher deleted the agents-md branch September 11, 2026 12:33
@UltralyticsAssistant

Copy link
Copy Markdown
Member

🎉 This PR has been merged—thank you, @glenn-jocher!

“Alone we can do so little; together we can do so much.” — Helen Keller

This collaboration improves generated Python multipart samples by opening binary files as file handles while preserving non-multipart behavior and generator coverage. Validation also passed 20 tests with 292 assertions, typecheck, lint, and knip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants