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

Fix span context manager typing by using ParamSpec from typing_extensions #4389

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

aabmass
Copy link
Member

@aabmass aabmass commented Jan 16, 2025

Description

Span context manager functions that use the _agnosticcontextmanager decorator (like start_as_current_span()) are currently of type Unknown when type checking for python <3.10 with pyright. This was coming up in open-telemetry/opentelemetry-python-contrib#3192 (failed run).

Also Fix #3836

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated

@aabmass aabmass changed the title Fix agnosticcontextmanager typing by using ParamSpec from typing_extensions Fix span context manager typing by using ParamSpec from typing_extensions Jan 16, 2025
@aabmass aabmass marked this pull request as ready for review January 16, 2025 22:19
@aabmass aabmass requested a review from a team as a code owner January 16, 2025 22:19
Copy link
Member

@emdneto emdneto left a comment

Choose a reason for hiding this comment

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

There is an issue I think is related and this PR also fix it: #3836

[tool.pyright]
pythonVersion = "3.8"
from opentelemetry import trace

tracer = trace.get_tracer(__name__)

with tracer.start_as_current_span(name="foo"):
    print("Hello world!")

With this pyright config and running the example against main, results in this error ❌ :

(main) $ pyright example.py 
/workspaces/opentelemetry-python/example.py
  /workspaces/opentelemetry-python/example.py:5:35 - error: No parameter named "name" (reportCallIssue)
1 error, 0 warnings, 0 informations 

Running against this branch results in ✅ :

(agnostic-type-fix) $ pyright example.py 
0 errors, 0 warnings, 0 informations 

@aabmass
Copy link
Member Author

aabmass commented Jan 17, 2025

Running against this branch results in ✅ :

Yup looks like the same issue 👍

@xrmx xrmx merged commit 58f2d16 into open-telemetry:main Jan 17, 2025
381 checks passed
@aabmass aabmass deleted the agnostic-type-fix branch January 17, 2025 16:13
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.

regression: typing error with start_as_current_span on Python<3.10
3 participants