confluent-kafka-python icon indicating copy to clipboard operation
confluent-kafka-python copied to clipboard

Type hint missing for "from confluent_kafka import Message"

Open 1st opened this issue 2 years ago • 10 comments

Description

The cimpl is a binary and IDE can't import definition from it.

image

How to reproduce

I see that in my VS Code IDE it's an error telling that it can't import the Message:

from confluent_kafka import Message
image

Checklist

Please provide the following information:

  • [x] confluent-kafka-python and librdkafka version (confluent_kafka.version() -> ('1.8.2', 17302016) and confluent_kafka.libversion() -> ('1.8.2', 17302271)):
  • [ ] Apache Kafka broker version:
  • [ ] Client configuration: {...}
  • [x] Operating system: Linux
  • [ ] Provide client logs (with 'debug': '..' as necessary)
  • [ ] Provide broker log excerpts
  • [ ] Critical issue

1st avatar Mar 29 '22 14:03 1st

I want to ask, how can I add the type stubs to be able to see the correct imports in the VS Code IDE? Do you provide such a way to import from the binary lib, but have the equal type definitions for such a classes/functions of the confluent_kafka lib?

1st avatar Mar 29 '22 14:03 1st

Found the reference to config the VS Code IDE, hope it can help: https://stackoverflow.com/a/68887896

jliunyu avatar Mar 30 '22 01:03 jliunyu

Seems like this is a wontfix for now: https://github.com/confluentinc/confluent-kafka-python/issues/1268#issuecomment-1017045748

martimors avatar Mar 30 '22 07:03 martimors

Seems like this is a wontfix for now: #1268 (comment)

So, do you plan to add stubs? We use Python 3.9 and most of the libs has stubs with type annotations and imports work perfectly. Only I found problems in your library, because it uses partially compiled files and import can't be done there.

1st avatar Mar 30 '22 08:03 1st

I'm not a contributer to this library, just trying to help out with some information 👍

martimors avatar Mar 30 '22 12:03 martimors

@1st I used mypy's stubgen and then some manual editing based on documentation / librdkafka code reading to add more info to the stubs for my project. It's still a WIP, and a bit of a PITA, but it can get you more type safety, slowly.

LiamClarkeNZ avatar Sep 14 '22 02:09 LiamClarkeNZ

i'd love to see type hints and good ide integration.

mhowlett avatar Oct 31 '22 18:10 mhowlett

Hi, it is 2024 and this is the only Python library I use that lacks proper typing support. Are you planning to do something about this?

MartinSoto avatar Mar 14 '24 16:03 MartinSoto