Skip to content

Commit e61b50d

Browse files
committed
Add a @requires_api_version decorator
1 parent 44e9299 commit e61b50d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

array_api_strict/_flags.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,21 @@ def set_flags_from_environment():
277277

278278
set_flags_from_environment()
279279

280+
# Decorators
281+
282+
def requires_api_version(version):
283+
def decorator(func):
284+
@functools.wraps(func)
285+
def wrapper(*args, **kwargs):
286+
if version > API_VERSION:
287+
raise RuntimeError(
288+
f"The function {func.__name__} requires API version {version} or later, "
289+
f"but the current API version for array-api-strict is {API_VERSION}"
290+
)
291+
return func(*args, **kwargs)
292+
return wrapper
293+
return decorator
294+
280295
def requires_data_dependent_shapes(func):
281296
@functools.wraps(func)
282297
def wrapper(*args, **kwargs):

0 commit comments

Comments
 (0)