Skip to content
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

Running mypy on sdk resources #773 #4360

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

prabhakarjuzgar
Copy link

Description

Addressing running mypy on opentelemetry-sdk iteratively so we don't have to make one big change addressing all mypy issues at once.

Fixes # (issue)

Type of change

Run mypy against SDK resources

How Has This Been Tested?

I executed the following tox commands:

  • tox -e mypy
  • tox -e test-opentelemetry-sdk
  • tox -e test-opentelemetry-api

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@prabhakarjuzgar prabhakarjuzgar requested a review from a team as a code owner December 16, 2024 21:02
Copy link
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes need to type check sdk resources? We are already checking it AFAICS, per mypy: mypy --install-types --non-interactive --namespace-packages --explicit-package-bases opentelemetry-sdk/src/opentelemetry/sdk/resources in tox.ini.

CHANGELOG.md Outdated Show resolved Hide resolved
return None

plugin_handled = False

error_handler_entry_points = entry_points(
error_handler_entry_points = entry_points( # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basedpyright: Import "opentelemetry.util._importlib_metadata" could not be resolved. This results in following errors when mypy is executed -

opentelemetry-sdk/src/opentelemetry/sdk/error_handler/init.py:119: error: Type of variable becomes "Any" due to an unfollowed import [no-any-unimported]
opentelemetry-sdk/src/opentelemetry/sdk/error_handler/init.py:119: error: Expression has type "Any" [misc]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xrmx Please let me know if the above errors can be handled differently.

Copy link
Contributor

@xrmx xrmx Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean something like this error_handler_entry_points : Entrypoints = entry_points(

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so my point is that it should have been found, but it's not.

Copy link
Author

@prabhakarjuzgar prabhakarjuzgar Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I changed
from importlib_metadata import (
to
from importlib.metadata import (
in https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py
mypy is able to find the imports. importlib_metadata is valid for python < 3.8.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update the PR to change importlib_metadata to imortlib.metadata and will remove ignore in the files -
opentelemetry-api/src/opentelemetry/context/__init__. opentelemetry-api/src/opentelemetry/propagate/__init__.py opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py opentelemetry-api/src/opentelemetry/util/_providers.py

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xrmx / @Kludex, Can this be suppressed with # type: ignore for the time.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think type: ignore should be used in any situation. It's usually a sign that something is wrong. At least the reason to ignore should be mentioned in the brackets. That's why I suggested this: #4360 (review)

I think the PR I opened should help you: #4368 (?)

@prabhakarjuzgar
Copy link
Author

Are these changes need to type check sdk resources? We are already checking it AFAICS, per mypy: mypy --install-types --non-interactive --namespace-packages --explicit-package-bases opentelemetry-sdk/src/opentelemetry/sdk/resources in tox.ini.

This does not execute mypy on sdk/src folder. Will add mypy: mypy --install-types --non-interactive --namespace-packages --explicit-package-bases opentelemetry-sdk/src to tox.ini after fixing all the files.

Copy link

@Kludex Kludex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be nice to enable https://docs.astral.sh/ruff/rules/blanket-type-ignore/#blanket-type-ignore-pgh003 to make it easier to understand on review what's the purpose of the ignores @xrmx

CHANGELOG.md Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants