Skip to content

Commit a4189cc

Browse files
authored
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 <module 'kubernetes' from 'C:\\Users\\Ark\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\kubernetes\\__init__.py'> >>> kubernetes.kubernetes <module 'kubernetes' from 'C:\\Users\\Ark\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\kubernetes\\__init__.py'> ``` 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`.
1 parent 4dddad8 commit a4189cc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

kubernetes/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016 The Kubernetes Authors.
1+
# Copyright 2022 The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
1616
# The version is auto-updated. Please do not edit.
1717
__version__ = "25.0.0-snapshot"
1818

19-
import kubernetes.client
20-
import kubernetes.config
21-
import kubernetes.dynamic
22-
import kubernetes.watch
23-
import kubernetes.stream
24-
import kubernetes.utils
25-
import kubernetes.leaderelection
19+
from . import client
20+
from . import config
21+
from . import dynamic
22+
from . import watch
23+
from . import stream
24+
from . import utils
25+
from . import leaderelection

0 commit comments

Comments
 (0)