@@ -56,20 +56,29 @@ def overload(x):
56
56
return x
57
57
58
58
59
- _HUB_DEPRECATION_MESSAGE = (
60
- "`sentry_sdk.Hub` is deprecated and will be removed in a future major release. "
61
- "Please consult our 1.x to 2.x migration guide for details on how to migrate "
62
- "`Hub` usage to the new API: "
63
- "https://docs.sentry.io/platforms/python/migration/1.x-to-2.x"
64
- )
59
+ class SentryHubDeprecationWarning (DeprecationWarning ):
60
+ """
61
+ A custom deprecation warning to inform users that the Hub is deprecated.
62
+ """
63
+
64
+ _MESSAGE = (
65
+ "`sentry_sdk.Hub` is deprecated and will be removed in a future major release. "
66
+ "Please consult our 1.x to 2.x migration guide for details on how to migrate "
67
+ "`Hub` usage to the new API: "
68
+ "https://docs.sentry.io/platforms/python/migration/1.x-to-2.x"
69
+ )
70
+
71
+ def __init__ (self , * args ):
72
+ # type: () -> None
73
+ super ().__init__ (self ._MESSAGE , * args )
65
74
66
75
67
76
@contextmanager
68
77
def _suppress_hub_deprecation_warning ():
69
78
# type: () -> Generator[None, None, None]
70
79
"""Utility function to suppress deprecation warnings for the Hub."""
71
80
with warnings .catch_warnings ():
72
- warnings .filterwarnings ("ignore" , _HUB_DEPRECATION_MESSAGE , DeprecationWarning )
81
+ warnings .filterwarnings ("ignore" , category = SentryHubDeprecationWarning )
73
82
yield
74
83
75
84
@@ -81,7 +90,7 @@ class HubMeta(type):
81
90
def current (cls ):
82
91
# type: () -> Hub
83
92
"""Returns the current instance of the hub."""
84
- warnings .warn (_HUB_DEPRECATION_MESSAGE , DeprecationWarning , stacklevel = 2 )
93
+ warnings .warn (SentryHubDeprecationWarning () , stacklevel = 2 )
85
94
rv = _local .get (None )
86
95
if rv is None :
87
96
with _suppress_hub_deprecation_warning ():
@@ -94,7 +103,7 @@ def current(cls):
94
103
def main (cls ):
95
104
# type: () -> Hub
96
105
"""Returns the main instance of the hub."""
97
- warnings .warn (_HUB_DEPRECATION_MESSAGE , DeprecationWarning , stacklevel = 2 )
106
+ warnings .warn (SentryHubDeprecationWarning , stacklevel = 2 )
98
107
return GLOBAL_HUB
99
108
100
109
@@ -125,7 +134,7 @@ def __init__(
125
134
scope = None , # type: Optional[Any]
126
135
):
127
136
# type: (...) -> None
128
- warnings .warn (_HUB_DEPRECATION_MESSAGE , DeprecationWarning , stacklevel = 2 )
137
+ warnings .warn (SentryHubDeprecationWarning () , stacklevel = 2 )
129
138
130
139
current_scope = None
131
140
0 commit comments