1
+ from __future__ import annotations
2
+
1
3
import abc
2
- import numbers
3
- import traceback
4
4
from contextlib import contextmanager
5
- from typing import Any , Generator , List , Optional , Sequence , Union
5
+ from typing import TYPE_CHECKING , Any , Generator , Sequence
6
+
7
+ if TYPE_CHECKING :
8
+ import numbers
9
+ import traceback
6
10
7
11
8
12
class BaseSegment (abc .ABC ):
9
13
"""Holds common properties and methods on segment and subsegment."""
10
14
11
15
@abc .abstractmethod
12
- def close (self , end_time : Optional [ int ] = None ):
16
+ def close (self , end_time : int | None = None ):
13
17
"""Close the trace entity by setting `end_time`
14
18
and flip the in progress flag to False.
15
19
@@ -28,7 +32,7 @@ def remove_subsegment(self, subsegment: Any):
28
32
"""Remove input subsegment from child subsegments."""
29
33
30
34
@abc .abstractmethod
31
- def put_annotation (self , key : str , value : Union [ str , numbers .Number , bool ] ) -> None :
35
+ def put_annotation (self , key : str , value : str | numbers .Number | bool ) -> None :
32
36
"""Annotate segment or subsegment with a key-value pair.
33
37
34
38
Note: Annotations will be indexed for later search query.
@@ -37,7 +41,7 @@ def put_annotation(self, key: str, value: Union[str, numbers.Number, bool]) -> N
37
41
----------
38
42
key: str
39
43
Metadata key
40
- value: Union[ str, numbers.Number, bool]
44
+ value: str | numbers.Number | bool
41
45
Annotation value
42
46
"""
43
47
@@ -52,19 +56,19 @@ def put_metadata(self, key: str, value: Any, namespace: str = "default") -> None
52
56
Metadata key
53
57
value: Any
54
58
Any object that can be serialized into a JSON string
55
- namespace: Set [str]
59
+ namespace: set [str]
56
60
Metadata namespace, by default 'default'
57
61
"""
58
62
59
63
@abc .abstractmethod
60
- def add_exception (self , exception : BaseException , stack : List [traceback .StackSummary ], remote : bool = False ):
64
+ def add_exception (self , exception : BaseException , stack : list [traceback .StackSummary ], remote : bool = False ):
61
65
"""Add an exception to trace entities.
62
66
63
67
Parameters
64
68
----------
65
69
exception: Exception
66
70
Caught exception
67
- stack: List [traceback.StackSummary]
71
+ stack: list [traceback.StackSummary]
68
72
List of traceback summaries
69
73
70
74
Output from `traceback.extract_stack()`.
@@ -83,7 +87,7 @@ def in_subsegment(self, name=None, **kwargs) -> Generator[BaseSegment, None, Non
83
87
----------
84
88
name: str
85
89
Subsegment name
86
- kwargs: Optional[ dict]
90
+ kwargs: dict | None
87
91
Optional parameters to be propagated to segment
88
92
"""
89
93
@@ -96,12 +100,12 @@ def in_subsegment_async(self, name=None, **kwargs) -> Generator[BaseSegment, Non
96
100
----------
97
101
name: str
98
102
Subsegment name
99
- kwargs: Optional[ dict]
103
+ kwargs: dict | None
100
104
Optional parameters to be propagated to segment
101
105
"""
102
106
103
107
@abc .abstractmethod
104
- def put_annotation (self , key : str , value : Union [ str , numbers .Number , bool ] ) -> None :
108
+ def put_annotation (self , key : str , value : str | numbers .Number | bool ) -> None :
105
109
"""Annotate current active trace entity with a key-value pair.
106
110
107
111
Note: Annotations will be indexed for later search query.
@@ -110,7 +114,7 @@ def put_annotation(self, key: str, value: Union[str, numbers.Number, bool]) -> N
110
114
----------
111
115
key: str
112
116
Metadata key
113
- value: Union[ str, numbers.Number, bool]
117
+ value: str | numbers.Number | bool
114
118
Annotation value
115
119
"""
116
120
@@ -126,7 +130,7 @@ def put_metadata(self, key: str, value: Any, namespace: str = "default") -> None
126
130
Metadata key
127
131
value: Any
128
132
Any object that can be serialized into a JSON string
129
- namespace: Set [str]
133
+ namespace: set [str]
130
134
Metadata namespace, by default 'default'
131
135
"""
132
136
@@ -136,7 +140,7 @@ def patch(self, modules: Sequence[str]) -> None:
136
140
137
141
Parameters
138
142
----------
139
- modules: Set [str]
143
+ modules: set [str]
140
144
Set of modules to be patched
141
145
"""
142
146
0 commit comments