File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -824,6 +824,23 @@ static PySequenceMethods Producer_seq_methods = {
824824 (lenfunc )Producer__len__ /* sq_length */
825825};
826826
827+ static int Producer__bool__ (Handle * self ) {
828+ return 1 ;
829+ }
830+
831+ static PyNumberMethods Producer_num_methods = {
832+ 0 , // nb_add
833+ 0 , // nb_subtract
834+ 0 , // nb_multiply
835+ 0 , // nb_remainder
836+ 0 , // nb_divmod
837+ 0 , // nb_power
838+ 0 , // nb_negative
839+ 0 , // nb_positive
840+ 0 , // nb_absolute
841+ (inquiry )Producer__bool__ // nb_bool
842+ };
843+
827844
828845static int Producer_init (PyObject * selfobj , PyObject * args , PyObject * kwargs ) {
829846 Handle * self = (Handle * )selfobj ;
@@ -879,8 +896,8 @@ PyTypeObject ProducerType = {
879896 0 , /*tp_setattr*/
880897 0 , /*tp_compare*/
881898 0 , /*tp_repr*/
882- 0 , /*tp_as_number*/
883- & Producer_seq_methods , /*tp_as_sequence*/
899+ & Producer_num_methods , /*tp_as_number*/
900+ & Producer_seq_methods , /*tp_as_sequence*/
884901 0 , /*tp_as_mapping*/
885902 0 , /*tp_hash */
886903 0 , /*tp_call*/
Original file line number Diff line number Diff line change @@ -271,3 +271,13 @@ def on_delivery(err, msg):
271271 p .purge ()
272272 p .flush (0.002 )
273273 assert cb_detector ["on_delivery_called" ]
274+
275+
276+ def test_producer_bool_value ():
277+ """
278+ Make sure producer has a truth-y bool value
279+ See https://github.com/confluentinc/confluent-kafka-python/issues/1427
280+ """
281+
282+ p = Producer ({})
283+ assert bool (p )
You can’t perform that action at this time.
0 commit comments