Skip to content

Commit 3936502

Browse files
feat(api): Remove sentry_sdk.push_scope (#3408)
Also, remove any tests that test `sentry_sdk.push_scope`. BREAKING CHANGE: Remove `sentry_sdk.push_scope`. Closes #3403
1 parent 275189e commit 3936502

File tree

7 files changed

+1
-633
lines changed

7 files changed

+1
-633
lines changed

docs/api.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,4 @@ Client Management
5151
Managing Scope (advanced)
5252
=========================
5353

54-
.. autofunction:: sentry_sdk.api.push_scope
55-
5654
.. autofunction:: sentry_sdk.api.new_scope

sentry_sdk/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"isolation_scope",
3333
"last_event_id",
3434
"new_scope",
35-
"push_scope",
3635
"set_context",
3736
"set_extra",
3837
"set_level",

sentry_sdk/api.py

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import inspect
2-
import warnings
32

43
from sentry_sdk import tracing_utils, Client
54
from sentry_sdk._init_implementation import init
6-
from sentry_sdk.scope import Scope, _ScopeManager, new_scope, isolation_scope
5+
from sentry_sdk.scope import Scope, new_scope, isolation_scope
76
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
87
from sentry_sdk.crons import monitor
98

@@ -16,10 +15,8 @@
1615
from typing import Any
1716
from typing import Dict
1817
from typing import Optional
19-
from typing import overload
2018
from typing import Callable
2119
from typing import TypeVar
22-
from typing import ContextManager
2320
from typing import Union
2421

2522
from typing_extensions import Unpack
@@ -39,11 +36,6 @@
3936

4037
T = TypeVar("T")
4138
F = TypeVar("F", bound=Callable[..., Any])
42-
else:
43-
44-
def overload(x):
45-
# type: (T) -> T
46-
return x
4739

4840

4941
# When changing this, update __all__ in __init__.py too
@@ -66,7 +58,6 @@ def overload(x):
6658
"isolation_scope",
6759
"last_event_id",
6860
"new_scope",
69-
"push_scope",
7061
"set_context",
7162
"set_extra",
7263
"set_level",
@@ -191,51 +182,6 @@ def add_breadcrumb(
191182
return get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)
192183

193184

194-
@overload
195-
def push_scope():
196-
# type: () -> ContextManager[Scope]
197-
pass
198-
199-
200-
@overload
201-
def push_scope( # noqa: F811
202-
callback, # type: Callable[[Scope], None]
203-
):
204-
# type: (...) -> None
205-
pass
206-
207-
208-
def push_scope( # noqa: F811
209-
callback=None, # type: Optional[Callable[[Scope], None]]
210-
):
211-
# type: (...) -> Optional[ContextManager[Scope]]
212-
"""
213-
Pushes a new layer on the scope stack.
214-
215-
:param callback: If provided, this method pushes a scope, calls
216-
`callback`, and pops the scope again.
217-
218-
:returns: If no `callback` is provided, a context manager that should
219-
be used to pop the scope again.
220-
"""
221-
warnings.warn(
222-
"sentry_sdk.push_scope is deprecated and will be removed in the next major version. "
223-
"Please consult our migration guide to learn how to migrate to the new API: "
224-
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-pushing",
225-
DeprecationWarning,
226-
stacklevel=2,
227-
)
228-
229-
if callback is not None:
230-
with warnings.catch_warnings():
231-
warnings.simplefilter("ignore", DeprecationWarning)
232-
with push_scope() as scope:
233-
callback(scope)
234-
return None
235-
236-
return _ScopeManager()
237-
238-
239185
@scopemethod
240186
def set_tag(key, value):
241187
# type: (str, Any) -> None

tests/new_scopes_compat/test_new_scopes_compat.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,6 @@
1111
"""
1212

1313

14-
def test_push_scope_sdk1(sentry_init, capture_events):
15-
"""
16-
Mutate data in a `with push_scope` block
17-
18-
Checks the results of SDK 2.x against the results the same code returned in SDK 1.x.
19-
"""
20-
sentry_init()
21-
22-
events = capture_events()
23-
24-
sentry_sdk.set_tag("A", 1)
25-
sentry_sdk.capture_message("Event A")
26-
27-
with sentry_sdk.push_scope() as scope: # push scope
28-
sentry_sdk.set_tag("B1", 1)
29-
scope.set_tag("B2", 1)
30-
sentry_sdk.capture_message("Event B")
31-
32-
sentry_sdk.set_tag("Z", 1)
33-
sentry_sdk.capture_message("Event Z")
34-
35-
(event_a, event_b, event_z) = events
36-
37-
# Check against the results the same code returned in SDK 1.x
38-
assert event_a["tags"] == {"A": 1}
39-
assert event_b["tags"] == {"A": 1, "B1": 1, "B2": 1}
40-
assert event_z["tags"] == {"A": 1, "Z": 1}
41-
42-
4314
def test_with_hub_sdk1(sentry_init, capture_events):
4415
"""
4516
Mutate data in a `with Hub:` block

0 commit comments

Comments
 (0)