From a95bde91ed17e5f6d041417236590379451e69e4 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Wed, 25 Jan 2023 16:59:12 +0100 Subject: [PATCH] Statically define __all__ for stable modules This prevents errors from typecheckers since they can now see that members are explicitly reexported --- .../src/opentelemetry/sdk/metrics/__init__.py | 28 ++++++++--------- .../sdk/metrics/export/__init__.py | 30 ++++++++++++++----- .../sdk/metrics/view/__init__.py | 20 +++++++------ 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py index 2219bc35c52..1ca14283cf6 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py @@ -12,16 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import -from opentelemetry.sdk.metrics._internal import ( # noqa: F401 - Meter, - MeterProvider, -) -from opentelemetry.sdk.metrics._internal.exceptions import ( # noqa: F401 - MetricsTimeoutError, -) -from opentelemetry.sdk.metrics._internal.instrument import ( # noqa: F401 +from opentelemetry.sdk.metrics._internal import Meter, MeterProvider +from opentelemetry.sdk.metrics._internal.exceptions import MetricsTimeoutError +from opentelemetry.sdk.metrics._internal.instrument import ( Counter, Histogram, ObservableCounter, @@ -30,8 +24,14 @@ UpDownCounter, ) -__all__ = [] -for key, value in globals().copy().items(): - if not key.startswith("_"): - value.__module__ = __name__ - __all__.append(key) +__all__ = [ + "Meter", + "MeterProvider", + "MetricsTimeoutError", + "Counter", + "Histogram", + "ObservableCounter", + "ObservableGauge", + "ObservableUpDownCounter", + "UpDownCounter", +] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py index 76021bd576d..a87beadce56 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import -from opentelemetry.sdk.metrics._internal.export import ( # noqa: F401 +from opentelemetry.sdk.metrics._internal.export import ( AggregationTemporality, ConsoleMetricExporter, InMemoryMetricReader, @@ -25,7 +24,7 @@ ) # The point module is not in the export directory to avoid a circular import. -from opentelemetry.sdk.metrics._internal.point import ( # noqa: F401 +from opentelemetry.sdk.metrics._internal.point import ( DataPointT, DataT, Gauge, @@ -39,8 +38,23 @@ Sum, ) -__all__ = [] -for key, value in globals().copy().items(): - if not key.startswith("_"): - value.__module__ = __name__ - __all__.append(key) +__all__ = [ + "AggregationTemporality", + "ConsoleMetricExporter", + "InMemoryMetricReader", + "MetricExporter", + "MetricExportResult", + "MetricReader", + "PeriodicExportingMetricReader", + "DataPointT", + "DataT", + "Gauge", + "Histogram", + "HistogramDataPoint", + "Metric", + "MetricsData", + "NumberDataPoint", + "ResourceMetrics", + "ScopeMetrics", + "Sum", +] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/view/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/view/__init__.py index b20053d876d..f6e4dcb3aae 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/view/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/view/__init__.py @@ -12,9 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import - -from opentelemetry.sdk.metrics._internal.aggregation import ( # noqa: F401 +from opentelemetry.sdk.metrics._internal.aggregation import ( Aggregation, DefaultAggregation, DropAggregation, @@ -22,10 +20,14 @@ LastValueAggregation, SumAggregation, ) -from opentelemetry.sdk.metrics._internal.view import View # noqa: F401 +from opentelemetry.sdk.metrics._internal.view import View -__all__ = [] -for key, value in globals().copy().items(): - if not key.startswith("_"): - value.__module__ = __name__ - __all__.append(key) +__all__ = [ + "Aggregation", + "DefaultAggregation", + "DropAggregation", + "ExplicitBucketHistogramAggregation", + "LastValueAggregation", + "SumAggregation", + "View", +]