-
Notifications
You must be signed in to change notification settings - Fork 652
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
PyLance / mypy doesn't accept opentelemetry
as a namespace package
#2591
Comments
I am not familiar with pylance but mypy checking should be working with |
I faced the same issue with pylance. This problem occurs because pylance does not see the file __init__.py in the /opentelemetry/ folder. If you add an file __init__.py to the root folder, then the pylance will work correctly. I assume that this is due to the fact that two packages (api and sdk), create files to the root directory of opentelemetry. If they added at least one place from api and sdk, then the problem would be solved. The same thing happens when installing exporters with not have the file __init__.py in the /opentelemetry/exporter/ folder! |
We intentionally don't have a We don't intend to change that, this looks like an issue of Pylance or mypy. I suggest we close this issue, thoughts @srikanthccv, @lzchen ? |
Instead of not including the |
It would be nice if someone could take this as something to research and come back with all the pros and cons between init.py and pkgutil-style. |
I'll start by asking Microsofties how their thinking goes. My guess: namespace packages is just not that common yet. |
This was fixed in microsoft/pylance-release#2562 — and there's an action point for this project to be more PEP-compatible:
Then it should all work |
@haf thanks for looking into this. I think that action item is reasonable, anyone want to take this issue? |
I ran into an issue typechecking import from opentelemetry-sdk Running
where test.py simply contains an import from opentelemetry-sdk
results in
Adding a Are there strong arguments against adding such a file ? I understand thata adding a Seen with python 3.8 and the following versions
|
@jenshnielsen for mypy you need to set I also had to add: [mypy-opentelemetry.sdk.*]
implicit_reexport = True It's a pity this info is not readily available in docs. |
@sk- Agreed! I actually came here to see if there was a good recommendation on where to put this in the python docs on the website (troubleshooting, additional section in getting started, additional section in manual instrumentation, something else, etc.) |
@sk- Thanks I figured out the same but forgot to post here. I find it a bit surprising that mypy requires you to set flags depending on details of your dependencies but that seems more like a mypy issue than a opentelemetry one. As in it's way more obvious that I have to set the namespace flag if I am typechecking a package that is it self a namespace package than when typechecking a package that happens to depend on a namespace package |
I opened this PR to see if we can add the necessary docs for mypy use: open-telemetry/opentelemetry.io#1611 |
Coming back to this I ran this in pyright (which pylance uses internally) microsoft/pyright#4520 which was closed as working as designed. Pyright considers opentelemetry.trace as untyped since there is no py.typed file in that module.
Could we please add py.typed files to the individual modules to conform with pep561 |
I think the issue is that |
Well actually since there’s no |
I have raised a PR - Link. |
The
opentelemetry-api
package, exportingopentelemetry
doesn't successfully import into vscode.import opentelemetry
is whitegives
It would seem this was solved a way back microsoft/pylance-release#555 but it's not
Describe your environment Describe any aspect of your environment relevant to the problem, including your Python version, platform, version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main.
Steps to reproduce
Install "opentelemetry" and see the import in VSCode.
What is the expected behavior?
I'd expect typing to work.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: