Skip to content

Commit

Permalink
fix: reimplementing __enter__ to avoid the type error.
Browse files Browse the repository at this point in the history
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
  • Loading branch information
QuentinN42 committed Feb 16, 2024
1 parent 20cbd9a commit acd649d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions opentelemetry-api/src/opentelemetry/util/_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ class that will decorate async functions with an async context manager
https://github.com/open-telemetry/opentelemetry-python/pull/3633
"""

def __enter__(self) -> R:
"""Reimplementing __enter__ to avoid the type error.
The original __enter__ method returns Any type, but we want to return R.
"""
del self.args, self.kwds, self.func
try:
return next(self.gen)
except StopIteration:
raise RuntimeError("generator didn't yield") from None

def __call__(self, func: V) -> V:
if asyncio.iscoroutinefunction(func):

Expand Down

0 comments on commit acd649d

Please sign in to comment.