@@ -72,10 +72,7 @@ def capture_event(
72
72
** scope_args # type: Dict[str, Any]
73
73
):
74
74
# type: (...) -> Optional[str]
75
- hub = Hub .current
76
- if hub is not None :
77
- return hub .capture_event (event , hint , scope = scope , ** scope_args )
78
- return None
75
+ return Hub .current .capture_event (event , hint , scope = scope , ** scope_args )
79
76
80
77
81
78
@hubmethod
@@ -86,10 +83,7 @@ def capture_message(
86
83
** scope_args # type: Dict[str, Any]
87
84
):
88
85
# type: (...) -> Optional[str]
89
- hub = Hub .current
90
- if hub is not None :
91
- return hub .capture_message (message , level , scope = scope , ** scope_args )
92
- return None
86
+ return Hub .current .capture_message (message , level , scope = scope , ** scope_args )
93
87
94
88
95
89
@hubmethod
@@ -99,10 +93,7 @@ def capture_exception(
99
93
** scope_args # type: Dict[str, Any]
100
94
):
101
95
# type: (...) -> Optional[str]
102
- hub = Hub .current
103
- if hub is not None :
104
- return hub .capture_exception (error , scope = scope , ** scope_args )
105
- return None
96
+ return Hub .current .capture_exception (error , scope = scope , ** scope_args )
106
97
107
98
108
99
@hubmethod
@@ -112,9 +103,7 @@ def add_breadcrumb(
112
103
** kwargs # type: Any
113
104
):
114
105
# type: (...) -> None
115
- hub = Hub .current
116
- if hub is not None :
117
- return hub .add_breadcrumb (crumb , hint , ** kwargs )
106
+ return Hub .current .add_breadcrumb (crumb , hint , ** kwargs )
118
107
119
108
120
109
@overload # noqa
@@ -136,19 +125,7 @@ def configure_scope(
136
125
callback = None , # type: Optional[Callable[[Scope], None]]
137
126
):
138
127
# type: (...) -> Optional[ContextManager[Scope]]
139
- hub = Hub .current
140
- if hub is not None :
141
- return hub .configure_scope (callback )
142
- elif callback is None :
143
-
144
- @contextmanager
145
- def inner ():
146
- yield Scope ()
147
-
148
- return inner ()
149
- else :
150
- # returned if user provided callback
151
- return None
128
+ return Hub .current .configure_scope (callback )
152
129
153
130
154
131
@overload # noqa
@@ -170,59 +147,37 @@ def push_scope(
170
147
callback = None , # type: Optional[Callable[[Scope], None]]
171
148
):
172
149
# type: (...) -> Optional[ContextManager[Scope]]
173
- hub = Hub .current
174
- if hub is not None :
175
- return hub .push_scope (callback )
176
- elif callback is None :
177
-
178
- @contextmanager
179
- def inner ():
180
- yield Scope ()
181
-
182
- return inner ()
183
- else :
184
- # returned if user provided callback
185
- return None
150
+ return Hub .current .push_scope (callback )
186
151
187
152
188
153
@scopemethod # noqa
189
154
def set_tag (key , value ):
190
155
# type: (str, Any) -> None
191
- hub = Hub .current
192
- if hub is not None :
193
- hub .scope .set_tag (key , value )
156
+ return Hub .current .scope .set_tag (key , value )
194
157
195
158
196
159
@scopemethod # noqa
197
160
def set_context (key , value ):
198
161
# type: (str, Any) -> None
199
- hub = Hub .current
200
- if hub is not None :
201
- hub .scope .set_context (key , value )
162
+ return Hub .current .scope .set_context (key , value )
202
163
203
164
204
165
@scopemethod # noqa
205
166
def set_extra (key , value ):
206
167
# type: (str, Any) -> None
207
- hub = Hub .current
208
- if hub is not None :
209
- hub .scope .set_extra (key , value )
168
+ return Hub .current .scope .set_extra (key , value )
210
169
211
170
212
171
@scopemethod # noqa
213
172
def set_user (value ):
214
173
# type: (Dict[str, Any]) -> None
215
- hub = Hub .current
216
- if hub is not None :
217
- hub .scope .set_user (value )
174
+ return Hub .current .scope .set_user (value )
218
175
219
176
220
177
@scopemethod # noqa
221
178
def set_level (value ):
222
179
# type: (str) -> None
223
- hub = Hub .current
224
- if hub is not None :
225
- hub .scope .set_level (value )
180
+ return Hub .current .scope .set_level (value )
226
181
227
182
228
183
@hubmethod
@@ -231,18 +186,13 @@ def flush(
231
186
callback = None , # type: Optional[Callable[[int, float], None]]
232
187
):
233
188
# type: (...) -> None
234
- hub = Hub .current
235
- if hub is not None :
236
- return hub .flush (timeout = timeout , callback = callback )
189
+ return Hub .current .flush (timeout = timeout , callback = callback )
237
190
238
191
239
192
@hubmethod
240
193
def last_event_id ():
241
194
# type: () -> Optional[str]
242
- hub = Hub .current
243
- if hub is not None :
244
- return hub .last_event_id ()
245
- return None
195
+ return Hub .current .last_event_id ()
246
196
247
197
248
198
@hubmethod
@@ -251,7 +201,4 @@ def start_span(
251
201
** kwargs # type: Any
252
202
):
253
203
# type: (...) -> Span
254
-
255
- # TODO: All other functions in this module check for
256
- # `Hub.current is None`. That actually should never happen?
257
204
return Hub .current .start_span (span = span , ** kwargs )
0 commit comments