Skip to content

Use six.add_metaclass for py2/py3 compatible abc #2551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions kafka/consumer/subscription_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def is_fetchable(self):
return not self.paused and self.has_valid_position


@six.add_metaclass(abc.ABCMeta)
class ConsumerRebalanceListener(object):
"""
A callback interface that the user can implement to trigger custom actions
Expand Down Expand Up @@ -462,8 +463,6 @@ class ConsumerRebalanceListener(object):
taking over that partition has their on_partitions_assigned() callback
called to load the state.
"""
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def on_partitions_revoked(self, revoked):
"""
Expand Down
4 changes: 2 additions & 2 deletions kafka/metrics/compound_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import abc

from kafka.metrics.stat import AbstractStat
from kafka.vendor.six import add_metaclass


@add_metaclass(abc.ABCMeta)
class AbstractCompoundStat(AbstractStat):
"""
A compound stat is a stat where a single measurement and associated
data structure feeds many metrics. This is the example for a
histogram which has many associated percentiles.
"""
__metaclass__ = abc.ABCMeta

def stats(self):
"""
Return list of NamedMeasurable
Expand Down
3 changes: 2 additions & 1 deletion kafka/metrics/measurable_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

from kafka.metrics.measurable import AbstractMeasurable
from kafka.metrics.stat import AbstractStat
from kafka.vendor.six import add_metaclass


@add_metaclass(abc.ABCMeta)
class AbstractMeasurableStat(AbstractStat, AbstractMeasurable):
"""
An AbstractMeasurableStat is an AbstractStat that is also
an AbstractMeasurable (i.e. can produce a single floating point value).
This is the interface used for most of the simple statistics such
as Avg, Max, Count, etc.
"""
__metaclass__ = abc.ABCMeta
5 changes: 3 additions & 2 deletions kafka/metrics/metrics_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import abc

from kafka.vendor.six import add_metaclass


@add_metaclass(abc.ABCMeta)
class AbstractMetricsReporter(object):
"""
An abstract class to allow things to listen as new metrics
are created so they can be reported.
"""
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def init(self, metrics):
"""
Expand Down
5 changes: 3 additions & 2 deletions kafka/metrics/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import abc

from kafka.vendor.six import add_metaclass


@add_metaclass(abc.ABCMeta)
class AbstractStat(object):
"""
An AbstractStat is a quantity such as average, max, etc that is computed
off the stream of updates to a sensor
"""
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def record(self, config, value, time_ms):
"""
Expand Down
4 changes: 2 additions & 2 deletions kafka/metrics/stats/sampled_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import abc

from kafka.metrics.measurable_stat import AbstractMeasurableStat
from kafka.vendor.six import add_metaclass


@add_metaclass(abc.ABCMeta)
class AbstractSampledStat(AbstractMeasurableStat):
"""
An AbstractSampledStat records a single scalar value measured over
Expand All @@ -20,8 +22,6 @@ class AbstractSampledStat(AbstractMeasurableStat):
Subclasses of this class define different statistics measured
using this basic pattern.
"""
__metaclass__ = abc.ABCMeta

def __init__(self, initial_value):
self._initial_value = initial_value
self._samples = []
Expand Down
5 changes: 3 additions & 2 deletions kafka/protocol/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import abc

from kafka.vendor.six import add_metaclass

class AbstractType(object):
__metaclass__ = abc.ABCMeta

@add_metaclass(abc.ABCMeta)
class AbstractType(object):
@abc.abstractmethod
def encode(cls, value): # pylint: disable=no-self-argument
pass
Expand Down
7 changes: 4 additions & 3 deletions kafka/protocol/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from kafka.protocol.struct import Struct
from kafka.protocol.types import Int16, Int32, String, Schema, Array, TaggedFields

from kafka.vendor.six import add_metaclass


class RequestHeader(Struct):
SCHEMA = Schema(
Expand Down Expand Up @@ -49,9 +51,8 @@ class ResponseHeaderV2(Struct):
)


@add_metaclass(abc.ABCMeta)
class Request(Struct):
__metaclass__ = abc.ABCMeta

FLEXIBLE_VERSION = False

@abc.abstractproperty
Expand Down Expand Up @@ -92,8 +93,8 @@ def parse_response_header(self, read_buffer):
return ResponseHeader.decode(read_buffer)


@add_metaclass(abc.ABCMeta)
class Response(Struct):
__metaclass__ = abc.ABCMeta

@abc.abstractproperty
def API_KEY(self):
Expand Down
11 changes: 7 additions & 4 deletions kafka/record/abc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from __future__ import absolute_import

import abc

from kafka.vendor.six import add_metaclass


@add_metaclass(abc.ABCMeta)
class ABCRecord(object):
__metaclass__ = abc.ABCMeta
__slots__ = ()

@abc.abstractproperty
Expand Down Expand Up @@ -44,8 +47,8 @@ def headers(self):
"""


@add_metaclass(abc.ABCMeta)
class ABCRecordBatchBuilder(object):
__metaclass__ = abc.ABCMeta
__slots__ = ()

@abc.abstractmethod
Expand Down Expand Up @@ -84,11 +87,11 @@ def build(self):
"""


@add_metaclass(abc.ABCMeta)
class ABCRecordBatch(object):
""" For v2 encapsulates a RecordBatch, for v0/v1 a single (maybe
compressed) message.
"""
__metaclass__ = abc.ABCMeta
__slots__ = ()

@abc.abstractmethod
Expand All @@ -98,8 +101,8 @@ def __iter__(self):
"""


@add_metaclass(abc.ABCMeta)
class ABCRecords(object):
__metaclass__ = abc.ABCMeta
__slots__ = ()

@abc.abstractmethod
Expand Down
5 changes: 3 additions & 2 deletions kafka/sasl/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import abc

from kafka.vendor.six import add_metaclass

class SaslMechanism(object):
__metaclass__ = abc.ABCMeta

@add_metaclass(abc.ABCMeta)
class SaslMechanism(object):
@abc.abstractmethod
def __init__(self, **config):
pass
Expand Down
Loading