Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different type hints will result in TypingError when using overload #9571

Open
dlee992 opened this issue May 13, 2024 · 3 comments · May be fixed by #9572
Open

Different type hints will result in TypingError when using overload #9571

dlee992 opened this issue May 13, 2024 · 3 comments · May be fixed by #9572
Labels
bug - typing Bugs: occuring at typing time

Comments

@dlee992
Copy link
Contributor

dlee992 commented May 13, 2024

test code:

""""""

from numba import njit, types
from numba.extending import overload


def generic_add(a, b):
    pass


@overload(generic_add)
def ol_generic_add(a: types.Number, b: types.Number):
    if isinstance(a, types.Integer) and isinstance(b, types.Integer):

        def impl(a: types.Integer, b: types.Integer):
            return a + b

        return impl

    elif isinstance(a, types.Float) and isinstance(b, types.Float):

        def impl(a: types.Float, b: types.Float):
            return a + b

        return impl


@njit
def foo():
    return generic_add(1, 2), generic_add(1.0, 2.0)


print(foo())

got TypingError:

    Rejected as the implementation raised a specific error:
      InternalError: Typing and implementation arguments differ in argument names.
    Typing signature:         (a: numba.core.types.abstract.Number, b: numba.core.types.abstract.Number)
    Implementation signature: (a: numba.core.types.scalars.Integer, b: numba.core.types.scalars.Integer)
    Difference: {<Parameter "a: numba.core.types.abstract.Number">, <Parameter "b: numba.core.types.scalars.Integer">, <Parameter "a: numba.core.types.scalars.Integer">, <Parameter "b: numba.core.types.abstract.Number">}

Somehow, numba regards type hints as parts of arguments, causing this error.
Perhaps before comparing arguments, shall we remove type hints first, given numba basically doesn't care type hints for now?

@dlee992 dlee992 linked a pull request May 13, 2024 that will close this issue
@guilhermeleobas guilhermeleobas added the bug - typing Bugs: occuring at typing time label May 14, 2024
@gmarkall
Copy link
Member

I think type hints are used for jitclass members: #5609

@dlee992
Copy link
Contributor Author

dlee992 commented May 14, 2024

I wonder why my PR didn't break the related tests for jitclass type annotation support.
The test cases:

    def test_type_annotations(self):
        spec = [("x", int32)]

        @jitclass(spec)
        class Test1(object):
            x: int
            y: pt.List[float]

            def __init__(self):
                pass

        self._check_spec(spec, Test1, spec + [("y", types.ListType(float64))])

    def test_type_annotation_inheritance(self):

        class Foo:
            x: int

        @jitclass
        class Bar(Foo):
            y: float

            def __init__(self, value: float) -> None:
                self.x = int(value)
                self.y = value

        self._check_spec(
            test_cls=Bar, all_expected=[("x", typeof(0)), ("y", typeof(0.0))]
        )

I guess the typing for class fields didn't go through the part I changed in OverloadTemplate?

@guilhermeleobas
Copy link
Collaborator

I'd bet that these are different things and the check that is it failing only applies to overloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - typing Bugs: occuring at typing time
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants