diff --git a/sdks/python/apache_beam/internal/metrics/cells.py b/sdks/python/apache_beam/internal/metrics/cells.py index 9a28ba46447a..989dc7183045 100644 --- a/sdks/python/apache_beam/internal/metrics/cells.py +++ b/sdks/python/apache_beam/internal/metrics/cells.py @@ -148,5 +148,5 @@ def combine(self, other: Optional['HistogramData']) -> 'HistogramData': return HistogramData(self.histogram.combine(other.histogram)) @staticmethod - def identity_element(bucket_type) -> HistogramData: + def identity_element(bucket_type) -> 'HistogramData': return HistogramData(Histogram(bucket_type)) diff --git a/sdks/python/apache_beam/metrics/cells.pxd b/sdks/python/apache_beam/metrics/cells.pxd index 807aff7fe76a..c583dabeb0c0 100644 --- a/sdks/python/apache_beam/metrics/cells.pxd +++ b/sdks/python/apache_beam/metrics/cells.pxd @@ -43,7 +43,7 @@ cdef class DistributionCell(MetricCell): cdef class AbstractMetricCell(MetricCell): cdef readonly object data_class - cdef readonly object data + cdef public object data cdef bint _update_locked(self, value) except -1 diff --git a/sdks/python/apache_beam/metrics/cells.py b/sdks/python/apache_beam/metrics/cells.py index ca74d50d1c85..10ac7b3a1e69 100644 --- a/sdks/python/apache_beam/metrics/cells.py +++ b/sdks/python/apache_beam/metrics/cells.py @@ -27,11 +27,9 @@ import threading import time from datetime import datetime -from typing import Any from typing import Iterable from typing import Optional from typing import Set -from typing import SupportsInt try: import cython @@ -233,7 +231,7 @@ def reset(self): self.data = self.data_class.identity_element() def combine(self, other: 'AbstractMetricCell') -> 'AbstractMetricCell': - result = type(self)() + result = type(self)() # type: ignore[call-arg] result.data = self.data.combine(other.data) return result @@ -506,7 +504,7 @@ def get_cumulative(self): # type: () -> DistributionData return DistributionData(self.sum, self.count, self.min, self.max) - def get_result(self): + def get_result(self) -> DistributionResult: return DistributionResult(self.get_cumulative()) def combine(self, other): diff --git a/sdks/python/apache_beam/runners/direct/direct_metrics.py b/sdks/python/apache_beam/runners/direct/direct_metrics.py index 693c0a64538e..d20849d769af 100644 --- a/sdks/python/apache_beam/runners/direct/direct_metrics.py +++ b/sdks/python/apache_beam/runners/direct/direct_metrics.py @@ -24,6 +24,8 @@ import threading from collections import defaultdict +from typing import Any +from typing import SupportsInt from apache_beam.metrics.cells import DistributionData from apache_beam.metrics.cells import GaugeData @@ -97,7 +99,7 @@ def __init__(self): self._distributions = defaultdict( lambda: DirectMetric(GenericAggregator(DistributionData))) self._gauges = defaultdict( - lambda: DirectMetric(GenericAggregator(GuageData))) + lambda: DirectMetric(GenericAggregator(GaugeData))) self._string_sets = defaultdict( lambda: DirectMetric(GenericAggregator(StringSetData)))