-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add the pkgutil style init file to datadog_checks_dev for support on IDEs language server #20483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
7e17300
to
20d8510
Compare
…IDEs language server
20d8510
to
5246020
Compare
Many of the checks are breaking because they are using relative imports. I know we were working on removing them in #20467 after having move ddev lint and formatter to ruff (in #20451). I will mark this PR draft until that is finished or it will take a long time to actually get everything refactored. |
What does this PR do?
This PR bring sback the
pkgutil
style__init__.py
file todatadog_checks_dev
that was removed previously in #19826.Motivation
Language servers like Pylance (used in VS Code) are currently unable to resolve imports from the
datadog_checks.dev
package. This leads to incorrect import errors within the IDE, which breaks features like autocompletion and "Go to Definition" for test fixtures. This change aims to fix this issue to improve the developer experience.This problem occurs because of an inconsistency in how the
datadog_checks
namespace package is defined:datadog-checks-base
package uses a legacypkgutil
-style namespace (which requires an__init__.py
file).datadog-checks-dev
package uses a modern implicit namespace (which omits the__init__.py
file).Static analysis tools see the
pkgutil
-style__init__.py
from the base package and correctly assume the entiredatadog_checks
namespace must follow that pattern. As a result, they do not discover thedev
package, which uses the conflicting implicit method.At runtime, this works because the code in the
pkgutil
__init__.py
file dynamically extends the package path to include thedev
directory. However, this runtime behavior cannot be inferred by static analysis, leading to the errors in the IDE.From the Native Namespace docs:
EDIT: After talking with @ofek and @iliakur we decided to go ahead and get rid of the need of using the old
pkgutil
by removing it from datadog-checks-base. We have been documenting the proper imports for years already and decided it was time to get rid of it.Review checklist (to be filled by reviewers)
qa/skip-qa
label if the PR doesn't need to be tested during QA.backport/<branch-name>
label to the PR and it will automatically open a backport PR once this one is merged