yummyPancake2607 commented on code in PR #4020:
URL: https://github.com/apache/iggy/pull/4020#discussion_r3939295468


##########
foreign/python/src/client_info.rs:
##########
@@ -0,0 +1,166 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+use iggy::prelude::ClientInfoDetails as RustClientInfoDetails;
+use iggy_common::{ClientInfo as RustClientInfo, ConsumerGroupInfo as 
RustConsumerGroupInfo};
+use pyo3::prelude::*;
+use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods};
+
+/// Information about a consumer group that a client is part of.
+#[gen_stub_pyclass]
+#[pyclass]
+pub struct ConsumerGroupInfo {
+    pub(crate) inner: RustConsumerGroupInfo,
+}
+
+impl From<RustConsumerGroupInfo> for ConsumerGroupInfo {
+    fn from(cg: RustConsumerGroupInfo) -> Self {
+        Self { inner: cg }
+    }
+}
+
+#[gen_stub_pymethods]
+#[pymethods]
+impl ConsumerGroupInfo {
+    /// The unique identifier (numeric) of the stream.
+    #[getter]
+    pub fn stream_id(&self) -> u32 {
+        self.inner.stream_id
+    }
+
+    /// The unique identifier (numeric) of the topic.
+    #[getter]
+    pub fn topic_id(&self) -> u32 {
+        self.inner.topic_id
+    }
+
+    /// The unique identifier (numeric) of the consumer group.
+    #[getter]
+    pub fn group_id(&self) -> u32 {
+        self.inner.group_id
+    }
+}
+
+/// Summary information about a connected client.
+#[gen_stub_pyclass]
+#[pyclass]
+pub struct ClientInfo {
+    pub(crate) inner: RustClientInfo,
+}
+
+impl From<RustClientInfo> for ClientInfo {
+    fn from(client: RustClientInfo) -> Self {
+        Self { inner: client }
+    }
+}
+
+#[gen_stub_pymethods]
+#[pymethods]
+impl ClientInfo {
+    /// The unique identifier of the client.
+    #[getter]
+    pub fn client_id(&self) -> u32 {
+        self.inner.client_id
+    }
+
+    /// The unique identifier of the authenticated user, or `None` if not 
authenticated.
+    #[getter]
+    pub fn user_id(&self) -> Option<u32> {
+        self.inner.user_id
+    }
+
+    /// The remote address of the client.
+    #[getter]
+    pub fn address(&self) -> String {
+        self.inner.address.clone()
+    }
+
+    /// The transport protocol used by the client.
+    #[getter]
+    pub fn transport(&self) -> String {
+        self.inner.transport.clone()
+    }
+
+    /// The number of consumer groups the client is part of.
+    #[getter]
+    pub fn consumer_groups_count(&self) -> u32 {
+        self.inner.consumer_groups_count
+    }
+}
+
+/// Detailed information about a connected client, including its consumer 
groups.
+#[gen_stub_pyclass]
+#[pyclass]
+pub struct ClientInfoDetails {
+    pub(crate) inner: RustClientInfoDetails,
+}
+
+impl From<RustClientInfoDetails> for ClientInfoDetails {
+    fn from(client: RustClientInfoDetails) -> Self {
+        Self { inner: client }
+    }
+}
+
+#[gen_stub_pymethods]
+#[pymethods]
+impl ClientInfoDetails {
+    /// The unique identifier of the client.
+    #[getter]
+    pub fn client_id(&self) -> u32 {
+        self.inner.client_id
+    }
+
+    /// The unique identifier of the authenticated user, or `None` if not 
authenticated.
+    #[getter]
+    pub fn user_id(&self) -> Option<u32> {
+        self.inner.user_id
+    }
+
+    /// The remote address of the client.
+    #[getter]
+    pub fn address(&self) -> String {
+        self.inner.address.clone()
+    }
+
+    /// The transport protocol used by the client.
+    #[getter]
+    pub fn transport(&self) -> String {
+        self.inner.transport.clone()
+    }
+
+    /// The number of consumer groups the client is part of.
+    #[getter]
+    pub fn consumer_groups_count(&self) -> u32 {
+        self.inner.consumer_groups_count
+    }
+
+    /// The consumer groups this client is part of.
+    #[getter]
+    pub fn consumer_groups(&self) -> Vec<ConsumerGroupInfo> {

Review Comment:
   I've added a docstring note to the `consumer_groups` getter warning that it 
rebuilds the list and allocates a fresh object per group on every attribute 
read. Callers should bind it once (e.g., `groups = d.consumer_groups`) to avoid 
identity comparison issues and unnecessary allocations.



##########
foreign/python/src/client_info.rs:
##########
@@ -0,0 +1,166 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+use iggy::prelude::ClientInfoDetails as RustClientInfoDetails;
+use iggy_common::{ClientInfo as RustClientInfo, ConsumerGroupInfo as 
RustConsumerGroupInfo};
+use pyo3::prelude::*;
+use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods};
+
+/// Information about a consumer group that a client is part of.
+#[gen_stub_pyclass]
+#[pyclass]
+pub struct ConsumerGroupInfo {
+    pub(crate) inner: RustConsumerGroupInfo,
+}
+
+impl From<RustConsumerGroupInfo> for ConsumerGroupInfo {
+    fn from(cg: RustConsumerGroupInfo) -> Self {
+        Self { inner: cg }
+    }
+}
+
+#[gen_stub_pymethods]
+#[pymethods]
+impl ConsumerGroupInfo {
+    /// The unique identifier (numeric) of the stream.
+    #[getter]
+    pub fn stream_id(&self) -> u32 {
+        self.inner.stream_id
+    }
+
+    /// The unique identifier (numeric) of the topic.
+    #[getter]
+    pub fn topic_id(&self) -> u32 {
+        self.inner.topic_id
+    }
+
+    /// The unique identifier (numeric) of the consumer group.
+    #[getter]
+    pub fn group_id(&self) -> u32 {
+        self.inner.group_id
+    }
+}
+
+/// Summary information about a connected client.
+#[gen_stub_pyclass]
+#[pyclass]
+pub struct ClientInfo {
+    pub(crate) inner: RustClientInfo,
+}
+
+impl From<RustClientInfo> for ClientInfo {
+    fn from(client: RustClientInfo) -> Self {
+        Self { inner: client }
+    }
+}
+
+#[gen_stub_pymethods]
+#[pymethods]
+impl ClientInfo {
+    /// The unique identifier of the client.
+    #[getter]
+    pub fn client_id(&self) -> u32 {
+        self.inner.client_id
+    }
+
+    /// The unique identifier of the authenticated user, or `None` if not 
authenticated.
+    #[getter]
+    pub fn user_id(&self) -> Option<u32> {
+        self.inner.user_id
+    }
+
+    /// The remote address of the client.
+    #[getter]
+    pub fn address(&self) -> String {
+        self.inner.address.clone()
+    }
+
+    /// The transport protocol used by the client.

Review Comment:
   I've updated the `transport` getter docstring to list the five fixed string 
values: `TCP`, `QUIC`, `HTTP`, `WebSocket`, `Unknown`. This is indeed the only 
place a Python caller learns the set of possible transport protocols.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to