Skip to content

fix(python): improve type annotation of the retries config key#23590

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
Gungy2:master
Apr 20, 2026
Merged

fix(python): improve type annotation of the retries config key#23590
wing328 merged 1 commit intoOpenAPITools:masterfrom
Gungy2:master

Conversation

@Gungy2
Copy link
Copy Markdown
Contributor

@Gungy2 Gungy2 commented Apr 20, 2026

The retries parameter in the Python client's Configuration.__init__ was typed as Optional[Union[int, Any]], which collapses to Optional[Any] and provides no useful type information to IDEs or type checkers.

The actual accepted types differ by HTTP library:

  • urllib3 (default): int or urllib3.util.retry.Retry
  • asyncio (aiohttp): int or aiohttp_retry.RetryOptionsBase
  • httpx: int only (retries not supported)

This change updates configuration.mustache to emit the correct type per library variant, and adds import aiohttp_retry for the asyncio case. All generated sample files are updated to match.

Since this is a Python change, I will tag the technical committee:
@cbornet @tomplus @krjakbrjak @fa0311 @multani

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes the Python client’s retries config typing to be transport-specific instead of Optional[Any], improving IDE hints and type checking for urllib3, aiohttp, and httpx.

  • Bug Fixes
    • Generate transport-specific types in Configuration.__init__: urllib3Optional[Union[int, urllib3.util.retry.Retry]], aiohttpOptional[Union[int, aiohttp_retry.RetryOptionsBase]], httpxOptional[int].
    • Add conditional import aiohttp_retry and update param docs to match each transport.
    • Update configuration.mustache and regenerate affected samples.

Written for commit 2edabf0. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py:280">
P2: `retries` parameter docs are stale and now contradict the updated `Optional[int]` constructor type, incorrectly referencing `aiohttp_retry` in the httpx client.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@Gungy2
Copy link
Copy Markdown
Contributor Author

Gungy2 commented Apr 20, 2026

@cubic-dev-ai

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Apr 20, 2026

@cubic-dev-ai

@Gungy2 I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 7 files

@wing328
Copy link
Copy Markdown
Member

wing328 commented Apr 20, 2026

thanks for the contribution.

lgtm. let's give it a try

@wing328 wing328 merged commit cc9cf08 into OpenAPITools:master Apr 20, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants