Explicitly Export PartitionMetadata to Satisfy Type Checkers#2225
Conversation
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
There was a problem hiding this comment.
Pull request overview
This PR makes PartitionMetadata explicitly re-exported from confluent_kafka.admin so type checkers (e.g., mypy with strict re-export rules) accept from confluent_kafka.admin import PartitionMetadata without requiring # type: ignore[attr-defined].
Changes:
- Split the
_metadataimports soPartitionMetadatais explicitly re-exported viafrom ... import PartitionMetadata as PartitionMetadata.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from ._metadata import BrokerMetadata # noqa: F401 | ||
| from ._metadata import ClusterMetadata, GroupMember, GroupMetadata, PartitionMetadata, TopicMetadata # noqa: F401 | ||
| from ._metadata import ClusterMetadata, GroupMember, GroupMetadata, TopicMetadata # noqa: F401 | ||
| from ._metadata import PartitionMetadata as PartitionMetadata # noqa: F401 |
There was a problem hiding this comment.
This adds an explicit re-export for PartitionMetadata, but the rest of the re-exported symbols in this module are still implicit from a type-checker perspective. To avoid having to special-case additional symbols later (and to make the public surface area unambiguous), consider defining an explicit __all__ for the admin package (or consistently using from ... import X as X for all intended re-exports).
What
At Sentry, we use this Python package to write Kafka consumers and producers. Some of our references the
PartitionMetadataclass, which is defined but not explicitly exported. As a result, when we attempt to import this class (and possibly others), type checking fails with an error like this one.This requires working around the type checker (specifically
mypy) with# type: ignore[attr-defined], defeating the purpose of using types in the first place.Checklist
PartitionMetadatais now explicitly exported.References
N/A
Test & Review
I tested these changes by pointing the Sentry monolith to this version of
confluent-kafkainstead of the published one. Follow these instructions to set up Sentry locally.Open Questions
PartitionMetadatato not be publicly exported?