Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include OWNERS
include *.md
include *.txt
include *.ini
include kubernetes/py.typed
include kubernetes/client/py.typed
exclude .gitignore
exclude .gitreview
Expand Down
1 change: 1 addition & 0 deletions kubernetes/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

78 changes: 78 additions & 0 deletions kubernetes/test/test_typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2026 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from importlib.resources import files
import unittest

from typing_extensions import assert_type

from kubernetes import client
from kubernetes.aio import client as aio_client


class TestPackageTyping(unittest.TestCase):
def test_root_package_is_marked_as_typed(self):
self.assertTrue(files('kubernetes').joinpath('py.typed').is_file())

def test_synchronous_nested_model_types(self):
pod = client.V1Pod(status=client.V1PodStatus(container_statuses=[
client.V1ContainerStatus(
image='image',
image_id='image-id',
name='container',
ready=True,
restart_count=0,
state=client.V1ContainerState(),
),
]))

status = assert_type(pod.status, client.V1PodStatus | None)
assert status is not None
containers = assert_type(
status.container_statuses,
list[client.V1ContainerStatus] | None,
)
assert containers is not None
state = assert_type(
containers[0].state,
client.V1ContainerState | None,
)
self.assertIsInstance(state, client.V1ContainerState)

def test_asynchronous_nested_model_types(self):
pod = aio_client.V1Pod(
status=aio_client.V1PodStatus(container_statuses=[
aio_client.V1ContainerStatus(
image='image',
image_id='image-id',
name='container',
ready=True,
restart_count=0,
state=aio_client.V1ContainerState(),
),
]),
)

status = assert_type(pod.status, aio_client.V1PodStatus | None)
assert status is not None
containers = assert_type(
status.container_statuses,
list[aio_client.V1ContainerStatus] | None,
)
assert containers is not None
state = assert_type(
containers[0].state,
aio_client.V1ContainerState | None,
)
self.assertIsInstance(state, aio_client.V1ContainerState)
5 changes: 4 additions & 1 deletion setup-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@
'kubernetes.aio.client.api',
'kubernetes.aio.client.models'
],
package_data={'kubernetes.client': ['py.typed']},
package_data={
'kubernetes': ['py.typed'],
'kubernetes.client': ['py.typed'],
},
include_package_data=True,
long_description="Python client for kubernetes http://kubernetes.io/",
python_requires='>=3.10',
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@
'kubernetes.leaderelection.resourcelock',
'kubernetes.informer',
],
package_data={'kubernetes.client': ['py.typed']},
package_data={
'kubernetes': ['py.typed'],
'kubernetes.client': ['py.typed'],
},

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.

setup-release.py also need this ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yliaog Yes—good catch. setup-release.py builds the combined synchronous and asyncio distribution, so updating only setup.py would leave published releases untyped.

Fixed in ca7fa34. I built the release wheel and source distribution and confirmed that both include kubernetes/py.typed as well as the existing synchronous and asyncio client markers. The nested-type regressions pass for both clients.

[tamirdex]

include_package_data=True,
long_description="Python client for kubernetes http://kubernetes.io/",
python_requires='>=3.10',
Expand Down