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

Making typed.List a typing Generic #5958

Merged
merged 26 commits into from
Feb 1, 2021
Merged
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3628b53
setting List as typing Generic
luk-f-a Jul 3, 2020
0857207
flake8 fix
luk-f-a Jul 3, 2020
c0015eb
adding annotation to len and contains
luk-f-a Jul 3, 2020
ece5174
fixes from review and new signatures
luk-f-a Nov 27, 2020
2f96450
Merge branch 'master' of https://github.com/numba/numba into typed-li…
luk-f-a Nov 27, 2020
4d0db93
additional fixes
luk-f-a Nov 27, 2020
aebe1e9
fixing wrong overload
luk-f-a Nov 27, 2020
fc3d5a0
flake8 fixes
luk-f-a Nov 27, 2020
c66c6b2
one more flake8 fix
luk-f-a Nov 27, 2020
a7b88f9
flake8 again
luk-f-a Nov 27, 2020
a6fcb13
several improvements following review and to make mypy pass
luk-f-a Nov 28, 2020
6529714
flake8
luk-f-a Nov 28, 2020
87fb3c7
adding py.typed file
luk-f-a Dec 5, 2020
4199351
Merge branch 'master' of https://github.com/numba/numba into typed-li…
luk-f-a Dec 5, 2020
2fd3e59
explicit optional inputs
luk-f-a Jan 6, 2021
c4f0139
Update numba/typed/typedlist.py
luk-f-a Jan 28, 2021
bb375b9
Update numba/typed/typedlist.py
luk-f-a Jan 28, 2021
4c725e3
Update numba/typed/typedlist.py
luk-f-a Jan 28, 2021
02fe12a
added _Sequence to deal with Sized sequences with getitem
luk-f-a Jan 28, 2021
9838739
importing Protocol from typing_extensions
luk-f-a Jan 28, 2021
e8294ca
fallback in case Protocol is not found in typing (pre Py 3.8)
luk-f-a Jan 29, 2021
a8c8edc
remove need for custom Protocol by removing getitem in extend
luk-f-a Jan 29, 2021
f4635de
Revert "remove need for custom Protocol by removing getitem in extend"
luk-f-a Jan 29, 2021
f511819
adds a python version guard
luk-f-a Jan 29, 2021
d9c80c2
flake8 fix
luk-f-a Jan 29, 2021
1dfa46f
less verbose check for python version
luk-f-a Jan 31, 2021
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
28 changes: 16 additions & 12 deletions numba/typed/typedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from numba.typed import listobject
from numba.core.errors import TypingError, LoweringError
from numba.core.typing.templates import Signature
from typing import TypeVar, Generic, Iterator
luk-f-a marked this conversation as resolved.
Show resolved Hide resolved

DEFAULT_ALLOCATED = listobject.DEFAULT_ALLOCATED

Expand Down Expand Up @@ -170,7 +171,10 @@ def _from_meminfo_ptr(ptr, listtype):
return List(meminfo=ptr, lsttype=listtype)


class List(MutableSequence):
T = TypeVar('T')


class List(MutableSequence, Generic[T]):
"""A typed-list usable in Numba compiled functions.

Implements the MutableSequence interface.
Expand Down Expand Up @@ -278,7 +282,7 @@ def _initialise_list(self, item):
lsttype = types.ListType(typeof(item))
self._list_type, self._opaque = self._parse_arg(lsttype)

def __len__(self):
def __len__(self) -> int:
if not self._typed:
return 0
else:
Expand Down Expand Up @@ -317,41 +321,41 @@ def __gt__(self, other):
def __ge__(self, other):
return _ge(self, other)

def append(self, item):
def append(self, item: T):
luk-f-a marked this conversation as resolved.
Show resolved Hide resolved
if not self._typed:
self._initialise_list(item)
_append(self, item)

def __setitem__(self, i, item):
def __setitem__(self, i, item: T):
if not self._typed:
self._initialise_list(item)
_setitem(self, i, item)

def __getitem__(self, i):
def __getitem__(self, i) -> T:
if not self._typed:
raise IndexError
else:
return _getitem(self, i)

def __iter__(self):
def __iter__(self) -> Iterator[T]:
for i in range(len(self)):
yield self[i]

def __contains__(self, item):
def __contains__(self, item: T) -> bool:
return _contains(self, item)

def __delitem__(self, i):
_delitem(self, i)

def insert(self, i, item):
def insert(self, i, item: T):
if not self._typed:
self._initialise_list(item)
_insert(self, i, item)

def count(self, item):
def count(self, item: T):
return _count(self, item)

def pop(self, i=-1):
def pop(self, i=-1) -> T:
luk-f-a marked this conversation as resolved.
Show resolved Hide resolved
return _pop(self, i)

def extend(self, iterable):
Expand All @@ -365,7 +369,7 @@ def extend(self, iterable):
self._initialise_list(iterable[0])
return _extend(self, iterable)

def remove(self, item):
def remove(self, item: T):
return _remove(self, item)

def clear(self):
Expand All @@ -377,7 +381,7 @@ def reverse(self):
def copy(self):
return _copy(self)

def index(self, item, start=None, stop=None):
def index(self, item: T, start=None, stop=None):
luk-f-a marked this conversation as resolved.
Show resolved Hide resolved
return _index(self, item, start, stop)

def sort(self, key=None, reverse=False):
Expand Down