Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/pylsl/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .lib import lib
from .info import StreamInfo
from .util import FOREVER
from .util import deprecated, FOREVER


def resolve_streams(wait_time=1.0):
Expand Down Expand Up @@ -166,7 +166,12 @@ def results(self):
return [StreamInfo(handle=buffer[k]) for k in range(num_found)]


@deprecated("Use `resolve_streams` instead.")
def resolve_stream(*args):
"""Resolve a stream.

This function is deprecated. Use `resolve_streams` instead.
"""
if len(args) == 0:
return resolve_streams()
elif type(args[0]) in [int, float]:
Expand Down
33 changes: 33 additions & 0 deletions src/pylsl/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import ctypes
import functools
import warnings

from .lib import lib

Expand Down Expand Up @@ -108,3 +110,34 @@ def handle_error(errcode):
raise InternalError("an internal error has occurred.")
elif errcode < 0:
raise RuntimeError("an unknown error has occurred.")


def deprecated(reason: str = None):
"""Mark functions as deprecated.

It will result in a warning being emitted when the function is used.

Example:
@deprecated("use new_function instead")
def old_function():
pass
"""
def decorator(func):
message = f"Function '{func.__name__}' is deprecated."
if reason:
message += f" {reason}"

@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.simplefilter("always", DeprecationWarning) # ensure it shows up
warnings.warn(
message,
category=DeprecationWarning,
stacklevel=2
)
warnings.simplefilter("default", DeprecationWarning)
return func(*args, **kwargs)

return wrapper

return decorator