From a4189ccf4e598f30c58020915b8eef81c138c84a Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Sun, 23 Oct 2022 17:50:50 -0700 Subject: [PATCH] Fixed double module imports In Python, when you write `import foo.bar.baz` this means that the modules would be imported and the name `foo` will be bound locally and becomes available in the module. https://docs.python.org/3/reference/simple_stmts.html#import So, doing `import kubernetes.client` leads to name `kubernetes` (not `client`) being added to the `kubernetes` module leading to a weird duplicate nesting. See: ``` >>> import kubernetes >>> kubernetes >>> kubernetes.kubernetes ``` We can solve this issues by using the `import ... from ...` syntax: Replace `import kubernetes.client` with `from kubernetes import client`. I see that most modules already use relative imports, so I'm using relative imports here as well: `from . import client`. --- kubernetes/__init__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kubernetes/__init__.py b/kubernetes/__init__.py index 63de84d88e..06adaf5fe0 100644 --- a/kubernetes/__init__.py +++ b/kubernetes/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2016 The Kubernetes Authors. +# Copyright 2022 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ # The version is auto-updated. Please do not edit. __version__ = "25.0.0-snapshot" -import kubernetes.client -import kubernetes.config -import kubernetes.dynamic -import kubernetes.watch -import kubernetes.stream -import kubernetes.utils -import kubernetes.leaderelection +from . import client +from . import config +from . import dynamic +from . import watch +from . import stream +from . import utils +from . import leaderelection