Skip to content

Commit ea85412

Browse files
committed
Avoid copies if possible
1 parent 1b71cf5 commit ea85412

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

sentry_sdk/scope.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,32 +236,40 @@ def __copy__(self):
236236
rv.client = self.client
237237
rv._level = self._level
238238
rv._name = self._name
239-
rv._fingerprint = self._fingerprint
239+
rv._fingerprint = self._fingerprint if self._fingerprint else None
240240
rv._transaction = self._transaction
241-
rv._transaction_info = self._transaction_info.copy()
241+
rv._transaction_info = (
242+
self._transaction_info.copy() if self._transaction_info else {}
243+
)
242244
rv._user = self._user
243245

244-
rv._tags = self._tags.copy()
245-
rv._contexts = self._contexts.copy()
246-
rv._extras = self._extras.copy()
246+
rv._tags = self._tags.copy() if self._tags else {}
247+
rv._contexts = self._contexts.copy() if self._contexts else {}
248+
rv._extras = self._extras.copy() if self._extras else {}
247249

248-
rv._breadcrumbs = copy(self._breadcrumbs)
250+
rv._breadcrumbs = copy(self._breadcrumbs) if self._breadcrumbs else {}
249251
rv._n_breadcrumbs_truncated = self._n_breadcrumbs_truncated
250-
rv._event_processors = self._event_processors.copy()
251-
rv._error_processors = self._error_processors.copy()
252-
rv._propagation_context = self._propagation_context
252+
rv._event_processors = (
253+
self._event_processors.copy() if self._event_processors else []
254+
)
255+
rv._error_processors = (
256+
self._error_processors.copy() if self._error_processors else []
257+
)
258+
rv._propagation_context = (
259+
self._propagation_context if self._propagation_context else None
260+
)
253261

254262
rv._should_capture = self._should_capture
255-
rv._span = self._span
256-
rv._session = self._session
263+
rv._span = self._span if self._span else None
264+
rv._session = self._session if self._session else None
257265
rv._force_auto_session_tracking = self._force_auto_session_tracking
258-
rv._attachments = self._attachments.copy()
266+
rv._attachments = self._attachments.copy() if self._attachments else []
259267

260-
rv._profile = self._profile
268+
rv._profile = self._profile if self._profile else None
261269

262270
rv._last_event_id = self._last_event_id
263271

264-
rv._flags = deepcopy(self._flags)
272+
rv._flags = deepcopy(self._flags) if self._flags else None
265273

266274
return rv
267275

0 commit comments

Comments
 (0)