Repository navigation
[Python] Add native lazy import support for Python 3.15 #25319
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
Open
Bernardoow
wants to merge
11
commits into
OpenAPITools:master
Choose a base branch
from
Bernardoow:add-support-to-python3.15v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
eaca252
add suport to lazy import and defer
Bernardoow 11ed859
Add support to python 3.15
Bernardoow 4a49266
fix break change at pycryptodome
Bernardoow e34d325
fix break change at pycryptodome
Bernardoow 41991c6
add missed ,
Bernardoow 3d5d5d2
remove 3.10 python
Bernardoow 53ee63c
remove 3.10 python
Bernardoow 582e5ed
Merge branch 'master' into rm-support-to-python3.10
Bernardoow 5ea99b7
update python.yml
Bernardoow 94b74b7
Add lazy loading native
Bernardoow 79bcd53
Merge branch 'master' into add-support-to-python3.15v2
Bernardoow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| name: "Python Client: Native lazy imports" | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - .github/workflows/samples-python-lazy-imports.yaml | ||
| - .mvn/** | ||
| - pom.xml | ||
| - modules/openapi-generator-core/** | ||
| - modules/openapi-generator/pom.xml | ||
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java | ||
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java | ||
| - modules/openapi-generator/src/main/resources/python/** | ||
| - modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java | ||
| - modules/openapi-generator/src/test/resources/3_1/python/lazy* | ||
|
|
||
| jobs: | ||
| runtime: | ||
| name: Native lazy imports runtime contracts (Python 3.15) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| - name: Set up JDK 11 | ||
| uses: actions/setup-java@v6 | ||
| with: | ||
| java-version: 11 | ||
| distribution: temurin | ||
| cache: maven | ||
| - name: Set up Python 3.15 | ||
| uses: actions/setup-python@v7 | ||
| id: py | ||
| with: | ||
| python-version: "3.15" | ||
| - name: Install runtime dependencies | ||
| run: >- | ||
| python -m pip install | ||
| "pydantic>=2.14" | ||
| "python-dateutil>=2.8.2" | ||
| "typing-extensions>=4.7.1" | ||
| "urllib3>=2.7.0,<3" | ||
| "aiohttp>=3.14.1" | ||
| "aiohttp-retry>=2.8.3" | ||
| "httpx>=0.28.1" | ||
| "httpx2>=2.13.0,<3" | ||
| - name: Test native lazy imports | ||
| run: >- | ||
| ./mvnw --batch-mode --no-snapshot-updates | ||
| -pl modules/openapi-generator -am test | ||
| -Dtest=PythonClientCodegenTest | ||
| -Dsurefire.failIfNoSpecifiedTests=false | ||
| -DpythonExecutable="${{ steps.py.outputs.python-path }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
modules/openapi-generator/src/main/resources/python/exports_api.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| # import apis into api package | ||
| {{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}} | ||
| {{#apiInfo}}{{#apis}}{{#lazyNativeImport}}lazy {{/lazyNativeImport}}from {{apiPackage}}.{{classFilename}} import {{classname}} | ||
| {{/apis}}{{/apiInfo}} |
2 changes: 1 addition & 1 deletion
2
modules/openapi-generator/src/main/resources/python/exports_model.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| # import models into model package | ||
| {{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}} | ||
| {{#models}}{{#model}}{{#lazyNativeImport}}lazy {{/lazyNativeImport}}from {{modelPackage}}.{{classFilename}} import {{classname}} | ||
| {{/model}}{{/models}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
modules/openapi-generator/src/main/resources/python/lazy_configuration.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| {{#lazyNativeImport}} | ||
| ### Native lazy imports | ||
|
|
||
| This client was generated with `lazyNativeImport=true` and requires Python 3.15+ | ||
| and Pydantic 2.14+. Its generated API and model imports use `lazy from`: modules | ||
| load on first use, so applications that use only a subset of a large client's | ||
| Pydantic models can avoid loading unused modules and reduce startup work and | ||
| initial memory use. | ||
|
|
||
| Import costs move to first use; import failures and module initialization side | ||
| effects can happen later. Evaluating type annotations, constructing schemas, or | ||
| using models can resolve lazy imports. Gains depend on the workload, and native | ||
| imports are not guaranteed to use less memory than `lazyImports=true`. | ||
| The two import options cannot be enabled together. | ||
| {{/lazyNativeImport}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
modules/openapi-generator/src/main/resources/python/travis.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Native-enabled README output merges the final lazy-import paragraph with the following packaging paragraph because this partial is not followed by a blank line. Add an empty line after the partial so Markdown renders them separately.
Prompt for AI agents