python: simplify lazy-import type-checking guards#24403
Conversation
|
@wing328 could you please TAL? |
|
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
left a comment
There was a problem hiding this comment.
This is clearer and easier to read than using __import__(). I don’t see any behavioral issues. LGTM.
|
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. |
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.