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

Improve type hints in opentelemetry.instrumentation.utils #3128

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

Conversation

Kludex
Copy link
Contributor

@Kludex Kludex commented Dec 20, 2024

No description provided.

@Kludex Kludex requested a review from a team as a code owner December 20, 2024 17:45
@@ -44,9 +44,9 @@


def extract_attributes_from_object(
obj: any, attributes: Sequence[str], existing: Dict[str, str] = None
obj: Any, attributes: Sequence[str], existing: Dict[str, str] | None = None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the most important change. any cannot be used as Any.

@@ -81,7 +83,7 @@ def http_status_to_status_code(
return StatusCode.ERROR


def unwrap(obj: Union[object, str], attr: str):
def unwrap(obj: object, attr: str):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a type of redundancy here, since str is an object.

But on the first line of this function, the type checker is able to infer if it's a str or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

The union has been added for humans more than for type checkers

@xrmx xrmx added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants