File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33from .lib import lib
44from .info import StreamInfo
5- from .util import FOREVER
5+ from .util import deprecated , FOREVER
66
77
88def resolve_streams (wait_time = 1.0 ):
@@ -166,7 +166,12 @@ def results(self):
166166 return [StreamInfo (handle = buffer [k ]) for k in range (num_found )]
167167
168168
169+ @deprecated ("Use `resolve_streams` instead." )
169170def resolve_stream (* args ):
171+ """Resolve a stream.
172+
173+ This function is deprecated. Use `resolve_streams` instead.
174+ """
170175 if len (args ) == 0 :
171176 return resolve_streams ()
172177 elif type (args [0 ]) in [int , float ]:
Original file line number Diff line number Diff line change 11import ctypes
2+ import functools
3+ import warnings
24
35from .lib import lib
46
@@ -108,3 +110,34 @@ def handle_error(errcode):
108110 raise InternalError ("an internal error has occurred." )
109111 elif errcode < 0 :
110112 raise RuntimeError ("an unknown error has occurred." )
113+
114+
115+ def deprecated (reason : str = None ):
116+ """Mark functions as deprecated.
117+
118+ It will result in a warning being emitted when the function is used.
119+
120+ Example:
121+ @deprecated("use new_function instead")
122+ def old_function():
123+ pass
124+ """
125+ def decorator (func ):
126+ message = f"Function '{ func .__name__ } ' is deprecated."
127+ if reason :
128+ message += f" { reason } "
129+
130+ @functools .wraps (func )
131+ def wrapper (* args , ** kwargs ):
132+ warnings .simplefilter ("always" , DeprecationWarning ) # ensure it shows up
133+ warnings .warn (
134+ message ,
135+ category = DeprecationWarning ,
136+ stacklevel = 2
137+ )
138+ warnings .simplefilter ("default" , DeprecationWarning )
139+ return func (* args , ** kwargs )
140+
141+ return wrapper
142+
143+ return decorator
You can’t perform that action at this time.
0 commit comments