Skip to content

Commit

Permalink
Deprecate external device annotation style (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermeleobas authored Aug 3, 2023
1 parent fc2ce64 commit ee8b93e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
19 changes: 3 additions & 16 deletions rbc/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"""


from rbc.utils import get_version
from numba.core.errors import TypingError
from numba.core.errors import NumbaTypeError, NumbaNotImplementedError, \
RequireLiteralValue, TypingError, \
DeprecationError # noqa: F401


class HeavyDBServerError(Exception):
Expand Down Expand Up @@ -43,17 +44,3 @@ class ForbiddenIntrinsicError(Exception):
https://github.com/xnd-project/rbc/issues/207
"""
pass


if get_version('numba') < (0, 55):
class NumbaTypeError(TypingError):
pass

class NumbaNotImplementedError(TypingError):
pass

class RequireLiteralValue(TypingError):
pass
else:
from numba.core.errors import NumbaTypeError, NumbaNotImplementedError, \
RequireLiteralValue # noqa: F401
5 changes: 2 additions & 3 deletions rbc/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
"""

# This code has heavily inspired in the numba.extending.intrisic code
import warnings
from typing import List, Union
from numba.core import extending, funcdesc, types, typing
from rbc.typesystem import Type
from rbc.targetinfo import TargetInfo
from rbc.errors import UnsupportedError
from rbc.errors import UnsupportedError, DeprecationError
from rbc.utils import validate_devices


Expand Down Expand Up @@ -44,7 +43,7 @@ def external(cls, signature, *, devices=['CPU']):
annotation_devices = validate_devices([d for d in t.annotation()
if d.upper() in {'CPU', 'GPU'}])
for d in annotation_devices:
warnings.warn(
raise DeprecationError(
f'Signature {signature} uses deprecated device annotation (`|{d}`).'
' Use `devices` kw argument to specify the supported devices of the'
f' external function `{name}`')
Expand Down
7 changes: 7 additions & 0 deletions rbc/tests/heavydb/test_external.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from rbc.tests import heavydb_fixture
from rbc.external import external
from rbc.errors import DeprecationError
from numba import types


Expand Down Expand Up @@ -59,3 +60,9 @@ def test_log2(a):
_, result = heavydb.sql_execute("select test_log2(8.0)")

assert list(result) == [(3.0,)]


def test_deprecated_device_annotation():
msg = r".* uses deprecated device annotation .*"
with pytest.raises(DeprecationError, match=msg):
_ = external('float64 cos(float64)|CPU')

0 comments on commit ee8b93e

Please sign in to comment.