@@ -74,18 +74,20 @@ static int NewTopic_init (PyObject *self0, PyObject *args,
74
74
"config" ,
75
75
NULL };
76
76
77
+ self -> num_partitions = -1 ;
77
78
self -> replication_factor = -1 ;
78
79
self -> replica_assignment = NULL ;
79
80
self -> config = NULL ;
80
81
81
- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "si|iOO " , kws ,
82
+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "s|iiOO " , kws ,
82
83
& topic , & self -> num_partitions ,
83
84
& self -> replication_factor ,
84
85
& self -> replica_assignment ,
85
86
& self -> config ))
86
87
return -1 ;
87
88
88
89
90
+
89
91
if (self -> config ) {
90
92
if (!PyDict_Check (self -> config )) {
91
93
PyErr_SetString (PyExc_TypeError ,
@@ -125,7 +127,8 @@ static PyMemberDef NewTopic_members[] = {
125
127
{ "topic" , T_STRING , offsetof(NewTopic , topic ), READONLY ,
126
128
":py:attribute:topic - Topic name (string)" },
127
129
{ "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" },
129
132
{ "replication_factor" , T_INT , offsetof(NewTopic , replication_factor ),
130
133
0 ,
131
134
" :py:attribute: Replication factor (int).\n"
@@ -147,6 +150,11 @@ static PyMemberDef NewTopic_members[] = {
147
150
148
151
149
152
static PyObject * NewTopic_str0 (NewTopic * self ) {
153
+ if (self -> num_partitions == -1 ) {
154
+ return cfl_PyUnistr (
155
+ _FromFormat ("NewTopic(topic=%s)" ,
156
+ self -> topic ));
157
+ }
150
158
return cfl_PyUnistr (
151
159
_FromFormat ("NewTopic(topic=%s,num_partitions=%d)" ,
152
160
self -> topic , self -> num_partitions ));
@@ -202,7 +210,12 @@ NewTopic_richcompare (NewTopic *self, PyObject *o2, int op) {
202
210
203
211
static long NewTopic_hash (NewTopic * self ) {
204
212
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
+ }
206
219
Py_DECREF (topic );
207
220
return r ;
208
221
}
@@ -233,12 +246,12 @@ PyTypeObject NewTopicType = {
233
246
"NewTopic specifies per-topic settings for passing to "
234
247
"AdminClient.create_topics().\n"
235
248
"\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"
237
250
"\n"
238
251
" Instantiate a NewTopic object.\n"
239
252
"\n"
240
253
" :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"
242
255
" :param int replication_factor: Replication factor of partitions, or -1 if replica_assignment is used.\n"
243
256
" :param list replica_assignment: List of lists with the replication assignment for each new partition.\n"
244
257
" :param dict config: Dict (str:str) of topic configuration. See http://kafka.apache.org/documentation.html#topicconfigs\n"
0 commit comments