@@ -56,20 +56,29 @@ def overload(x):
5656 return x
5757
5858
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 )
6574
6675
6776@contextmanager
6877def _suppress_hub_deprecation_warning ():
6978 # type: () -> Generator[None, None, None]
7079 """Utility function to suppress deprecation warnings for the Hub."""
7180 with warnings .catch_warnings ():
72- warnings .filterwarnings ("ignore" , _HUB_DEPRECATION_MESSAGE , DeprecationWarning )
81+ warnings .filterwarnings ("ignore" , category = SentryHubDeprecationWarning )
7382 yield
7483
7584
@@ -81,7 +90,7 @@ class HubMeta(type):
8190 def current (cls ):
8291 # type: () -> Hub
8392 """Returns the current instance of the hub."""
84- warnings .warn (_HUB_DEPRECATION_MESSAGE , DeprecationWarning , stacklevel = 2 )
93+ warnings .warn (SentryHubDeprecationWarning () , stacklevel = 2 )
8594 rv = _local .get (None )
8695 if rv is None :
8796 with _suppress_hub_deprecation_warning ():
@@ -94,7 +103,7 @@ def current(cls):
94103 def main (cls ):
95104 # type: () -> Hub
96105 """Returns the main instance of the hub."""
97- warnings .warn (_HUB_DEPRECATION_MESSAGE , DeprecationWarning , stacklevel = 2 )
106+ warnings .warn (SentryHubDeprecationWarning , stacklevel = 2 )
98107 return GLOBAL_HUB
99108
100109
@@ -125,7 +134,7 @@ def __init__(
125134 scope = None , # type: Optional[Any]
126135 ):
127136 # type: (...) -> None
128- warnings .warn (_HUB_DEPRECATION_MESSAGE , DeprecationWarning , stacklevel = 2 )
137+ warnings .warn (SentryHubDeprecationWarning () , stacklevel = 2 )
129138
130139 current_scope = None
131140
0 commit comments