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

Add type annotations for @intrinsic #9401

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
warn_unused_configs = True
follow_imports = silent
show_error_context = True
files = **/numba/core/types/*.py, **/numba/core/datamodel/*.py, **/numba/core/rewrites/*.py, **/numba/core/unsafe/*.py, **/numba/core/rvsdg_frontend/*.py, **/numba/core/rvsdg_frontend/rvsdg/*.py
files = **/numba/core/types/*.py, **/numba/core/extending.py, **/numba/core/datamodel/*.py, **/numba/core/rewrites/*.py, **/numba/core/unsafe/*.py, **/numba/core/rvsdg_frontend/*.py, **/numba/core/rvsdg_frontend/rvsdg/*.py

# Per-module options:
# To classify a given module as Level 1, 2 or 3 it must be added both in files (variable above) and in the lists below.
Expand Down
2 changes: 2 additions & 0 deletions numba/_helperlib.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def _import_cython_function(module_name: str, function_name: str):
...
5 changes: 3 additions & 2 deletions numba/core/extending.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,11 @@ class _Intrinsic(ReduceMixin):
"""
Dummy callable for intrinsic
"""
_memo = weakref.WeakValueDictionary()
_memo: weakref.WeakValueDictionary = weakref.WeakValueDictionary()
__cache_size = config.FUNCTION_CACHE_SIZE # type: ignore
# hold refs to last N functions deserialized, retaining them in _memo
# regardless of whether there is another reference
_recent = collections.deque(maxlen=config.FUNCTION_CACHE_SIZE)
_recent: collections.deque = collections.deque(maxlen=__cache_size)

__uuid = None

Expand Down
128 changes: 128 additions & 0 deletions numba/core/extending.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import collections
import sys
import weakref

from numba.core.serialize import ReduceMixin


def type_callable(func):
...


def overload(func, jit_options={}, strict=True, inline='never',
prefer_literal=False, **kwargs):
...


def register_jitable(*args, **kwargs):
...


def overload_attribute(typ, attr, **kwargs):
...


def _overload_method_common(typ, attr, **kwargs):
...


def overload_method(typ, attr, **kwargs):
...


def overload_classmethod(typ, attr, **kwargs):
...


def make_attribute_wrapper(typeclass, struct_attr, python_attr):
...


class _Intrinsic(ReduceMixin, Generic[P, R]):
_memo: weakref.WeakValueDictionary
_recent: collections.deque

def __init__(
self,
name,
defn: Callable[Concatenate[object, P], R],
prefer_literal=False,
**kwargs
):
...

@property
def _uuid(self):
...

def _set_uuid(self, u):
...

def _register(self):
...

def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
...

def __repr__(self):
...

def __deepcopy__(self, memo):
...

def _reduce_states(self):
...

@classmethod
def _rebuild(cls, uuid, name, defn):
...


if sys.version_info >= (3, 10):
from typing import Callable, Concatenate, Generic, ParamSpec, TypeVar

# Type of the parameters of the function being converted to an intrinsic,
# excluding the typing context parameter.
P = ParamSpec("P")
# Return type of the function being converted to an intrinsic
R = TypeVar("R")

def intrinsic(*args, **kwargs) -> Callable[
[Callable[Concatenate[object, P], R]],
Callable[P, R]
]:
...
else:
def intrinsic(*args, **kwargs):
...


def get_cython_function_address(module_name, function_name):
...


def include_path():
...


def sentry_literal_args(pysig, literal_args, args, kwargs):
...


class SentryLiteralArgs(collections.namedtuple(
'_SentryLiteralArgs', ['literal_args'])):
def for_function(self, func):
...

def for_pysig(self, pysig):
...


class BoundLiteralArgs(collections.namedtuple(
'BoundLiteralArgs', ['pysig', 'literal_args'])):
def bind(self, *args, **kwargs):
...


def is_jitted(function):
...