From c1c28a8ab07ca280d5183b914ede5ab14b8d1c00 Mon Sep 17 00:00:00 2001 From: Ojasva Jain Date: Wed, 19 Nov 2025 12:11:04 +0530 Subject: [PATCH 1/4] update documentation for msg object instantiation with warning --- src/confluent_kafka/src/confluent_kafka.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/confluent_kafka/src/confluent_kafka.c b/src/confluent_kafka/src/confluent_kafka.c index 09c57efa9..20b35cc61 100644 --- a/src/confluent_kafka/src/confluent_kafka.c +++ b/src/confluent_kafka/src/confluent_kafka.c @@ -849,7 +849,24 @@ PyTypeObject MessageType = { "An application must check with :py:func:`error()` to see if the " "object is a proper message (error() returns None) or an " "error/event.\n" - "\n" + "\n" + ".. py:function:: Message([topic], [partition], [offset], [key], [value], [headers], [error], [timestamp], [latency], [leader_epoch])\n" + "\n" + " Instantiate a Message object. This is primarily intended for " + "testing and mock scenarios (e.g. unit tests). All parameters are optional.\n" + "\n" + " :param string topic: Topic name\n" + " :param int partition: Partition number\n" + " :param int offset: Message offset\n" + " :param bytes key: Message key\n" + " :param bytes value: Message value\n" + " :param list headers: Message headers\n" + " :param KafkaError error: KafkaError object\n" + " :param tuple timestamp: (Timestamp type (int), Message epoch timestamp in seconds (int))\n" + " :param float latency: Message latency in seconds\n" + " :param int leader_epoch: Message leader epoch in seconds\n" + " :rtype: Message\n" + "\n" ".. py:function:: len()\n" "\n" " :returns: Message value (payload) size in bytes\n" From 6ccac019d7d4fc8c072afe9e77402149c62f9b12 Mon Sep 17 00:00:00 2001 From: Ojasva Jain Date: Wed, 19 Nov 2025 19:16:54 +0530 Subject: [PATCH 2/4] add warning block as suggested --- src/confluent_kafka/src/confluent_kafka.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/confluent_kafka/src/confluent_kafka.c b/src/confluent_kafka/src/confluent_kafka.c index 20b35cc61..498d74c4f 100644 --- a/src/confluent_kafka/src/confluent_kafka.c +++ b/src/confluent_kafka/src/confluent_kafka.c @@ -852,8 +852,15 @@ PyTypeObject MessageType = { "\n" ".. py:function:: Message([topic], [partition], [offset], [key], [value], [headers], [error], [timestamp], [latency], [leader_epoch])\n" "\n" - " Instantiate a Message object. This is primarily intended for " - "testing and mock scenarios (e.g. unit tests). All parameters are optional.\n" + " Instantiate a Message object.\n" + "\n" + " .. warning::" + " This constructor is intended **only for testing and mock scenarios**." + " Do **not** use user instantiated Message object in mainstream APIs or in production." + " Using this constructor outside of test environments may result in" + " unexpected behavior, security issues, or inconsistent application state.\n" + "\n" + " All parameters are optional.\n" "\n" " :param string topic: Topic name\n" " :param int partition: Partition number\n" From 0a1cce97125aa321c7bd8798c3cb2a81166010e5 Mon Sep 17 00:00:00 2001 From: Ojasva Jain Date: Thu, 20 Nov 2025 11:58:24 +0530 Subject: [PATCH 3/4] fix whitespace --- src/confluent_kafka/src/confluent_kafka.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/confluent_kafka/src/confluent_kafka.c b/src/confluent_kafka/src/confluent_kafka.c index 498d74c4f..23699e66b 100644 --- a/src/confluent_kafka/src/confluent_kafka.c +++ b/src/confluent_kafka/src/confluent_kafka.c @@ -859,7 +859,7 @@ PyTypeObject MessageType = { " Do **not** use user instantiated Message object in mainstream APIs or in production." " Using this constructor outside of test environments may result in" " unexpected behavior, security issues, or inconsistent application state.\n" - "\n" + "\n" " All parameters are optional.\n" "\n" " :param string topic: Topic name\n" From 83bd7a96ee42f955c7f3b6ef7db475987cac920c Mon Sep 17 00:00:00 2001 From: Ojasva Jain Date: Thu, 20 Nov 2025 12:10:26 +0530 Subject: [PATCH 4/4] fix code formatting --- src/confluent_kafka/src/confluent_kafka.c | 148 +++++++++++----------- 1 file changed, 75 insertions(+), 73 deletions(-) diff --git a/src/confluent_kafka/src/confluent_kafka.c b/src/confluent_kafka/src/confluent_kafka.c index 3cd600ae5..6a1924cf7 100644 --- a/src/confluent_kafka/src/confluent_kafka.c +++ b/src/confluent_kafka/src/confluent_kafka.c @@ -789,80 +789,82 @@ static PySequenceMethods Message_seq_methods = { }; PyTypeObject MessageType = { - PyVarObject_HEAD_INIT(NULL, 0) - "cimpl.Message", /*tp_name*/ - sizeof(Message), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)Message_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - &Message_seq_methods, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - PyObject_GenericGetAttr, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "The Message object represents either a single consumed or " - "produced message, or an event (:py:func:`error()` is not None).\n" - "\n" - "An application must check with :py:func:`error()` to see if the " - "object is a proper message (error() returns None) or an " - "error/event.\n" - "\n" - ".. py:function:: Message([topic], [partition], [offset], [key], [value], [headers], [error], [timestamp], [latency], [leader_epoch])\n" - "\n" - " Instantiate a Message object.\n" - "\n" - " .. warning::" - " This constructor is intended **only for testing and mock scenarios**." - " Do **not** use user instantiated Message object in mainstream APIs or in production." - " Using this constructor outside of test environments may result in" - " unexpected behavior, security issues, or inconsistent application state.\n" + PyVarObject_HEAD_INIT(NULL, 0) "cimpl.Message", /*tp_name*/ + sizeof(Message), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)Message_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &Message_seq_methods, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + PyObject_GenericGetAttr, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "The Message object represents either a single consumed or " + "produced message, or an event (:py:func:`error()` is not None).\n" + "\n" + "An application must check with :py:func:`error()` to see if the " + "object is a proper message (error() returns None) or an " + "error/event.\n" + "\n" + ".. py:function:: Message([topic], [partition], [offset], [key], [value], " + "[headers], [error], [timestamp], [latency], [leader_epoch])\n" + "\n" + " Instantiate a Message object.\n" + "\n" + " .. warning::" + " This constructor is intended **only for testing and mock scenarios**." + " Do **not** use user instantiated Message object in mainstream APIs or " + "in production." + " Using this constructor outside of test environments may result in" + " unexpected behavior, security issues, or inconsistent application " + "state.\n" + "\n" + " All parameters are optional.\n" + "\n" + " :param string topic: Topic name\n" + " :param int partition: Partition number\n" + " :param int offset: Message offset\n" + " :param bytes key: Message key\n" + " :param bytes value: Message value\n" + " :param list headers: Message headers\n" + " :param KafkaError error: KafkaError object\n" + " :param tuple timestamp: (Timestamp type (int), Message epoch timestamp " + "in seconds (int))\n" + " :param float latency: Message latency in seconds\n" + " :param int leader_epoch: Message leader epoch in seconds\n" + " :rtype: Message\n" + "\n" + ".. py:function:: len()\n" "\n" - " All parameters are optional.\n" - "\n" - " :param string topic: Topic name\n" - " :param int partition: Partition number\n" - " :param int offset: Message offset\n" - " :param bytes key: Message key\n" - " :param bytes value: Message value\n" - " :param list headers: Message headers\n" - " :param KafkaError error: KafkaError object\n" - " :param tuple timestamp: (Timestamp type (int), Message epoch timestamp in seconds (int))\n" - " :param float latency: Message latency in seconds\n" - " :param int leader_epoch: Message leader epoch in seconds\n" - " :rtype: Message\n" - "\n" - ".. py:function:: len()\n" - "\n" - " :returns: Message value (payload) size in bytes\n" - " :rtype: int\n" - "\n", /*tp_doc*/ - (traverseproc)Message_traverse, /* tp_traverse */ - (inquiry)Message_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - Message_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - Message_init, /* tp_init */ - 0, /* tp_alloc */ - Message_new /* tp_new */ + " :returns: Message value (payload) size in bytes\n" + " :rtype: int\n" + "\n", /*tp_doc*/ + (traverseproc)Message_traverse, /* tp_traverse */ + (inquiry)Message_clear, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + Message_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + Message_init, /* tp_init */ + 0, /* tp_alloc */ + Message_new /* tp_new */ }; /**