DataDog / datadogpy

The Datadog Python library
https://datadoghq.com/
Other
611 stars 302 forks source link

Type checking errors with datadog client due to private imports #830

Open adamh-oai opened 5 months ago

adamh-oai commented 5 months ago

Describe the bug The documented way of accessing dogstatsd is from datadog import statsd. This is a re-export of another module, in datadog/__init__.py:

from datadog.dogstatsd import DogStatsd, statsd

Unfortunately, the typechecker in VSCode (pyright) flags this as use of a private module:

"statsd" is not exported from module "datadog".  Import from "datadog.dogstatsd.base" instead.

The fix for this is to use a convention for re-exporting a module publically is:

from datadog.dogstatsd import DogStatsd as DogStatsd, statsd as statsd

I would put up a PR for this but I'm not sure which modules are intended as public interfaces from the top-level module.

To Reproduce

Steps to reproduce the behavior:

Create a project with this pyproject.toml:

[tool.poetry]
name = "dd-type-repro"
version = "0.1.0"
description = ""
authors = ["Adam Hupp <adamh@openai.com>"]

[tool.poetry.dependencies]
python = "^3.11"
datadog = "*"
pyright = "^1.1.360"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

And put this in main.py:

from datadog import statsd

And run poetry run pyright:

/Users/adamh/dd-type-repro/main.py
  /Users/adamh/dd-type-repro/main.py:1:21 - error: "statsd" is not exported from module "datadog"
    Import from "datadog.dogstatsd.base" instead (reportPrivateImportUsage)
1 error, 0 warnings, 0 informations

Expected behavior No type errors in normal use.

github-actions[bot] commented 4 months ago

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.

If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of this project.

  2. Comment that the issue is still reproducible and include updated details requested in the issue template.

tyleryle commented 4 months ago

Issue is still active.

github-actions[bot] commented 3 months ago

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.

If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of this project.

  2. Comment that the issue is still reproducible and include updated details requested in the issue template.