@@ -74,18 +74,20 @@ static int NewTopic_init (PyObject *self0, PyObject *args,
7474 "config" ,
7575 NULL };
7676
77+ self -> num_partitions = -1 ;
7778 self -> replication_factor = -1 ;
7879 self -> replica_assignment = NULL ;
7980 self -> config = NULL ;
8081
81- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "si|iOO " , kws ,
82+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "s|iiOO " , kws ,
8283 & topic , & self -> num_partitions ,
8384 & self -> replication_factor ,
8485 & self -> replica_assignment ,
8586 & self -> config ))
8687 return -1 ;
8788
8889
90+
8991 if (self -> config ) {
9092 if (!PyDict_Check (self -> config )) {
9193 PyErr_SetString (PyExc_TypeError ,
@@ -125,7 +127,8 @@ static PyMemberDef NewTopic_members[] = {
125127 { "topic" , T_STRING , offsetof(NewTopic , topic ), READONLY ,
126128 ":py:attribute:topic - Topic name (string)" },
127129 { "num_partitions" , T_INT , offsetof(NewTopic , num_partitions ), 0 ,
128- ":py:attribute: Number of partitions (int)" },
130+ ":py:attribute: Number of partitions (int).\n"
131+ "Or -1 if a replica_assignment is specified" },
129132 { "replication_factor" , T_INT , offsetof(NewTopic , replication_factor ),
130133 0 ,
131134 " :py:attribute: Replication factor (int).\n"
@@ -147,6 +150,11 @@ static PyMemberDef NewTopic_members[] = {
147150
148151
149152static PyObject * NewTopic_str0 (NewTopic * self ) {
153+ if (self -> num_partitions == -1 ) {
154+ return cfl_PyUnistr (
155+ _FromFormat ("NewTopic(topic=%s)" ,
156+ self -> topic ));
157+ }
150158 return cfl_PyUnistr (
151159 _FromFormat ("NewTopic(topic=%s,num_partitions=%d)" ,
152160 self -> topic , self -> num_partitions ));
@@ -202,7 +210,12 @@ NewTopic_richcompare (NewTopic *self, PyObject *o2, int op) {
202210
203211static long NewTopic_hash (NewTopic * self ) {
204212 PyObject * topic = cfl_PyUnistr (_FromString (self -> topic ));
205- long r = PyObject_Hash (topic ) ^ self -> num_partitions ;
213+ long r ;
214+ if (self -> num_partitions == -1 ) {
215+ r = PyObject_Hash (topic );
216+ } else {
217+ r = PyObject_Hash (topic ) ^ self -> num_partitions ;
218+ }
206219 Py_DECREF (topic );
207220 return r ;
208221}
@@ -233,12 +246,12 @@ PyTypeObject NewTopicType = {
233246 "NewTopic specifies per-topic settings for passing to "
234247 "AdminClient.create_topics().\n"
235248 "\n"
236- ".. py:function:: NewTopic(topic, num_partitions, [replication_factor], [replica_assignment], [config])\n"
249+ ".. py:function:: NewTopic(topic, [ num_partitions] , [replication_factor], [replica_assignment], [config])\n"
237250 "\n"
238251 " Instantiate a NewTopic object.\n"
239252 "\n"
240253 " :param string topic: Topic name\n"
241- " :param int num_partitions: Number of partitions to create\n"
254+ " :param int num_partitions: Number of partitions to create, or -1 if replica_assignment is used. \n"
242255 " :param int replication_factor: Replication factor of partitions, or -1 if replica_assignment is used.\n"
243256 " :param list replica_assignment: List of lists with the replication assignment for each new partition.\n"
244257 " :param dict config: Dict (str:str) of topic configuration. See http://kafka.apache.org/documentation.html#topicconfigs\n"
0 commit comments