Skip to content

Commit e987c5a

Browse files
Merge pull request #2657 from tamird/prototype/mark-kubernetes-package-typed
Mark the Kubernetes package as typed
2 parents 16929fc + ca7fa34 commit e987c5a

5 files changed

Lines changed: 88 additions & 2 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ include OWNERS
33
include *.md
44
include *.txt
55
include *.ini
6+
include kubernetes/py.typed
67
include kubernetes/client/py.typed
78
exclude .gitignore
89
exclude .gitreview

kubernetes/py.typed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

kubernetes/test/test_typing.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright 2026 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from importlib.resources import files
16+
import unittest
17+
18+
from typing_extensions import assert_type
19+
20+
from kubernetes import client
21+
from kubernetes.aio import client as aio_client
22+
23+
24+
class TestPackageTyping(unittest.TestCase):
25+
def test_root_package_is_marked_as_typed(self):
26+
self.assertTrue(files('kubernetes').joinpath('py.typed').is_file())
27+
28+
def test_synchronous_nested_model_types(self):
29+
pod = client.V1Pod(status=client.V1PodStatus(container_statuses=[
30+
client.V1ContainerStatus(
31+
image='image',
32+
image_id='image-id',
33+
name='container',
34+
ready=True,
35+
restart_count=0,
36+
state=client.V1ContainerState(),
37+
),
38+
]))
39+
40+
status = assert_type(pod.status, client.V1PodStatus | None)
41+
assert status is not None
42+
containers = assert_type(
43+
status.container_statuses,
44+
list[client.V1ContainerStatus] | None,
45+
)
46+
assert containers is not None
47+
state = assert_type(
48+
containers[0].state,
49+
client.V1ContainerState | None,
50+
)
51+
self.assertIsInstance(state, client.V1ContainerState)
52+
53+
def test_asynchronous_nested_model_types(self):
54+
pod = aio_client.V1Pod(
55+
status=aio_client.V1PodStatus(container_statuses=[
56+
aio_client.V1ContainerStatus(
57+
image='image',
58+
image_id='image-id',
59+
name='container',
60+
ready=True,
61+
restart_count=0,
62+
state=aio_client.V1ContainerState(),
63+
),
64+
]),
65+
)
66+
67+
status = assert_type(pod.status, aio_client.V1PodStatus | None)
68+
assert status is not None
69+
containers = assert_type(
70+
status.container_statuses,
71+
list[aio_client.V1ContainerStatus] | None,
72+
)
73+
assert containers is not None
74+
state = assert_type(
75+
containers[0].state,
76+
aio_client.V1ContainerState | None,
77+
)
78+
self.assertIsInstance(state, aio_client.V1ContainerState)

setup-release.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@
8080
'kubernetes.aio.client.api',
8181
'kubernetes.aio.client.models'
8282
],
83-
package_data={'kubernetes.client': ['py.typed']},
83+
package_data={
84+
'kubernetes': ['py.typed'],
85+
'kubernetes.client': ['py.typed'],
86+
},
8487
include_package_data=True,
8588
long_description="Python client for kubernetes http://kubernetes.io/",
8689
python_requires='>=3.10',

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@
6767
'kubernetes.leaderelection.resourcelock',
6868
'kubernetes.informer',
6969
],
70-
package_data={'kubernetes.client': ['py.typed']},
70+
package_data={
71+
'kubernetes': ['py.typed'],
72+
'kubernetes.client': ['py.typed'],
73+
},
7174
include_package_data=True,
7275
long_description="Python client for kubernetes http://kubernetes.io/",
7376
python_requires='>=3.10',

0 commit comments

Comments
 (0)