Skip to content

python: simplify lazy-import type-checking guards#24403

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
tamird:fix/python-type-checking-import
Jul 25, 2026
Merged

python: simplify lazy-import type-checking guards#24403
wing328 merged 1 commit into
OpenAPITools:masterfrom
tamird:fix/python-type-checking-import

Conversation

@tamird

@tamird tamird commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The lazy Python initializers use dynamic __import__ to reach typing.TYPE_CHECKING, an idiom introduced alongside lazy-imports in c4a7c14.

Use a private standard-library typing module import instead. This keeps type-checking branches statically recognizable, avoids shadowing generated models named TYPE_CHECKING, and leaves clients without lazy imports unchanged.

@tamird
tamird marked this pull request as ready for review July 23, 2026 18:11
@tamird

tamird commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@wing328 could you please TAL?

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 6 files

Re-trigger cubic

@wing328

wing328 commented Jul 24, 2026

Copy link
Copy Markdown
Member

thanks for the PR. will review and try to get it merged

cc @cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10)

@fa0311 fa0311 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is clearer and easier to read than using __import__(). I don’t see any behavioral issues. LGTM.

@tamird

tamird commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @wing328! FYI this is going to have a minor merge conflict with #24402 which is a much more important but also more complex change. I would be very thankful if you could prioritize landing both. They are currently required to unblock updating kubernetes-client to the latest openapi-generator release, which is a very big milestone! See discussion in kubernetes-client/python#2631.

Thanks for your help so far! I'm very excited to ship this long-overdue update for kubernetes-python.

@wing328
wing328 merged commit d8b78d4 into OpenAPITools:master Jul 25, 2026
42 checks passed
@tamird
tamird deleted the fix/python-type-checking-import branch July 25, 2026 13:15
@tamird
tamird restored the fix/python-type-checking-import branch July 25, 2026 13:15
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.

3 participants