Skip to content

Commit

Permalink
Statically define __all__ for stable modules
Browse files Browse the repository at this point in the history
This prevents errors from typecheckers since
they can now see that members are explicitly reexported
  • Loading branch information
jenshnielsen committed Jan 25, 2023
1 parent 8f312c4 commit a95bde9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
28 changes: 14 additions & 14 deletions opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
]
30 changes: 22 additions & 8 deletions opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
]
20 changes: 11 additions & 9 deletions opentelemetry-sdk/src/opentelemetry/sdk/metrics/view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@
# 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,
ExplicitBucketHistogramAggregation,
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",
]

0 comments on commit a95bde9

Please sign in to comment.