Skip to content

Dynamically generated __all__ in opentelemetry sdk does not work with static type checkers #3141

@jenshnielsen

Description

@jenshnielsen

Describe your environment

mypy with no-implicit-reexport enabled
pyright with default settings

Any OS or python version

Steps to reproduce

type check a line like

from opentelemetry.sdk.metrics import MeterProvider,

or open it in vscode with pylance and pyright enabled

What is the expected behavior?

Code to typecheck

What is the actual behavior?
Error such as (from pylance/pyright)

"MeterProvider" is not exported from module "opentelemetry.sdk.metrics"
  Import from "opentelemetry.sdk.metrics._internal" insteadPylance[reportPrivateImportUsage](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportPrivateImportUsage)

Additional context

This is caused by __all__ being dynamically generated for example here https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py

The docs suggests to disable implicit_reexport as implemented here open-telemetry/opentelemetry.io#1611

This is problematic for a number of reasons.

It doesn't actually fix the issue with pyright/pylance

The implicit reexport feature is very useful and makes it much easier to spot that you are unintentionally importing symbols from the wrong location. Doing it like recommended disables this feature for all packages.

Would it be possible to replace those dynamically generated __all__s with static ones

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions