Skip to content

Commit ad15c7a

Browse files
fix(tracer): declare in_subsegment_async as an async context manager (#8367)
BaseProvider.in_subsegment_async was decorated with @contextmanager and annotated to return Generator[BaseSegment, None, None], declaring a synchronous context manager. It is entered with async with by Tracer._decorate_async_function, by the documented escape hatch for concurrent async functions, and by the default X-Ray provider. Remove the decorator and annotate the return type as AbstractAsyncContextManager[BaseSegment] so correct code type checks without a cast. No runtime change, the abstract method body is only a docstring. Closes #8365 Co-authored-by: Leandro Damascena <lcdama@amazon.pt>
1 parent dccd850 commit ad15c7a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • aws_lambda_powertools/tracing

‎aws_lambda_powertools/tracing/base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import numbers
1515
import traceback
1616
from collections.abc import Generator, Sequence
17+
from contextlib import AbstractAsyncContextManager
1718

1819

1920
class BaseSegment(abc.ABC):
@@ -99,8 +100,7 @@ def in_subsegment(self, name=None, **kwargs) -> Generator[BaseSegment, None, Non
99100
"""
100101

101102
@abc.abstractmethod
102-
@contextmanager
103-
def in_subsegment_async(self, name=None, **kwargs) -> Generator[BaseSegment, None, None]:
103+
def in_subsegment_async(self, name=None, **kwargs) -> AbstractAsyncContextManager[BaseSegment]:
104104
"""Return a subsegment async context manger.
105105
106106
Parameters

0 commit comments

Comments
 (0)