From 329d51b54a9073358f0c8147b2f37917e73b7d8a Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 9 Jan 2020 18:21:18 -0700 Subject: [PATCH 1/7] typing for sortedlist --- setup.py | 2 ++ sortedcontainers/py.typed | 0 sortedcontainers/sorteddict.py | 12 ++++++------ sortedcontainers/sortedset.py | 14 +++++++------- 4 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 sortedcontainers/py.typed diff --git a/setup.py b/setup.py index 80ddf03f..4b9555a2 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,8 @@ def run_tests(self): url='http://www.grantjenks.com/docs/sortedcontainers/', license='Apache 2.0', packages=['sortedcontainers'], + package_data={'sortedcontainers':["py.typed", "sortedlist.pyi"]}, + zip_safe=False, tests_require=['tox'], cmdclass={'test': Tox}, install_requires=[], diff --git a/sortedcontainers/py.typed b/sortedcontainers/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/sortedcontainers/sorteddict.py b/sortedcontainers/sorteddict.py index ec68c6e5..325ea6b7 100644 --- a/sortedcontainers/sorteddict.py +++ b/sortedcontainers/sorteddict.py @@ -384,12 +384,12 @@ def method(self): method.__doc__ = message return property(method) - iteritems = __make_raise_attributeerror('iteritems', 'items') - iterkeys = __make_raise_attributeerror('iterkeys', 'keys') - itervalues = __make_raise_attributeerror('itervalues', 'values') - viewitems = __make_raise_attributeerror('viewitems', 'items') - viewkeys = __make_raise_attributeerror('viewkeys', 'keys') - viewvalues = __make_raise_attributeerror('viewvalues', 'values') + iteritems = __make_raise_attributeerror('iteritems', 'items') # type: ignore + iterkeys = __make_raise_attributeerror('iterkeys', 'keys') # type: ignore + itervalues = __make_raise_attributeerror('itervalues', 'values') # type: ignore + viewitems = __make_raise_attributeerror('viewitems', 'items') # type: ignore + viewkeys = __make_raise_attributeerror('viewkeys', 'keys') # type: ignore + viewvalues = __make_raise_attributeerror('viewvalues', 'values') # type: ignore class _NotGiven(object): diff --git a/sortedcontainers/sortedset.py b/sortedcontainers/sortedset.py index be2b8999..ff81f370 100644 --- a/sortedcontainers/sortedset.py +++ b/sortedcontainers/sortedset.py @@ -294,13 +294,13 @@ def comparer(self, other): return comparer - __eq__ = __make_cmp(eq, '==', 'equal to') - __ne__ = __make_cmp(ne, '!=', 'not equal to') - __lt__ = __make_cmp(lt, '<', 'a proper subset of') - __gt__ = __make_cmp(gt, '>', 'a proper superset of') - __le__ = __make_cmp(le, '<=', 'a subset of') - __ge__ = __make_cmp(ge, '>=', 'a superset of') - __make_cmp = staticmethod(__make_cmp) + __eq__ = __make_cmp(eq, '==', 'equal to') # type: ignore + __ne__ = __make_cmp(ne, '!=', 'not equal to') # type: ignore + __lt__ = __make_cmp(lt, '<', 'a proper subset of') # type: ignore + __gt__ = __make_cmp(gt, '>', 'a proper superset of') # type: ignore + __le__ = __make_cmp(le, '<=', 'a subset of') # type: ignore + __ge__ = __make_cmp(ge, '>=', 'a superset of') # type: ignore + __make_cmp = staticmethod(__make_cmp) # type: ignore def __len__(self): From ae9e79b1717fb8cb3e69c0e2842aeeabdb02afc9 Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 9 Jan 2020 18:23:10 -0700 Subject: [PATCH 2/7] typing for sortedlist --- sortedcontainers/sortedlist.pyi | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 sortedcontainers/sortedlist.pyi diff --git a/sortedcontainers/sortedlist.pyi b/sortedcontainers/sortedlist.pyi new file mode 100644 index 00000000..ea1b0113 --- /dev/null +++ b/sortedcontainers/sortedlist.pyi @@ -0,0 +1,82 @@ +from typing import Any, Callable, Iterable, MutableSequence, Optional, Tuple, TypeVar, Generic, Iterator + + +def recursive_repr(fillvalue: str = ...): ... +T = TypeVar('T', covariant=True) + +class SortedList(MutableSequence[T]): + DEFAULT_LOAD_FACTOR: int = ... + def __init__(self, iterable: Iterable[T]=..., key: None=...) -> None: ... + def __new__(cls: Any, iterable: Iterable[T]=..., key: Callable[[T], Any]=...) -> SortedList[T]: ... + @property + def key(self) -> Optional[Callable[[T], Any]]: ... + def clear(self) -> None: ... + def add(self, value) -> None: ... + def update(self, iterable: Iterable[T]) -> Any: ... + def __contains__(self, value) -> bool: ... + def discard(self, value) -> None: ... + def remove(self, value) -> None: ... + def __delitem__(self, index: Any): ... + def __getitem__(self, index: Any): ... + def __setitem__(self, index: Any, value: Any) -> None: ... + def __iter__(self) -> Iterator[T]: ... + def __reversed__(self) -> Iterator[T]: ... + def reverse(self) -> None: ... + def islice(self, start: int=..., stop: int=..., reverse: bool=...) -> Iterable[T]: ... + def irange(self, minimum=..., maximum=..., inclusive: Tuple[bool, bool]=..., reverse: bool=...) -> Any: ... + def __len__(self) -> int: ... + def bisect_left(self, value) -> int: ... + def bisect_right(self, value) -> int: ... + bisect: Any = ... + def count(self, value) -> int: ... + def copy(self) -> SortedList[T]: ... + __copy__: Any = ... + def append(self, value: Any) -> None: ... + def extend(self, values: Any) -> None: ... + def insert(self, index: Any, value: Any) -> None: ... + def pop(self, index: int=...) -> T: ... + def index(self, value: Any, start: int=..., stop: int=...) -> int: ... + def __add__(self, other: SortedList[T]) -> SortedList[T]: ... + __radd__: Any = ... + def __iadd__(self, other: Iterable[T])-> SortedList[T]: ... + def __mul__(self, num: int) -> SortedList[T]: ... + __rmul__: Any = ... + def __imul__(self, num: int) -> SortedList[T]: ... + __eq__: Any = ... + __ne__: Any = ... + __lt__: Any = ... + __gt__: Any = ... + __le__: Any = ... + __ge__: Any = ... + def __reduce__(self): ... + +def identity(value: Any) -> T: ... + +class SortedKeyList(SortedList[T]): + def __init__(self, iterable: Iterable[T]=..., key: Callable[[T], Any]=...) -> None: ... + def __new__(cls: Any, iterable: Iterable[T]=..., key: Callable[[T], Any]=...) -> Any: ... + @property + def key(self) -> Callable[[T], Any]: ... + def clear(self) -> None: ... + def add(self, value) -> None: ... + def update(self, iterable: Iterable[T]) -> None: ... + def __contains__(self, value) -> bool: ... + def discard(self, value) -> None: ... + def remove(self, value) -> None: ... + def irange(self, minimum=..., maximum=..., inclusive: Tuple[bool, bool]=..., reverse: bool=...) -> Any: ... + def irange_key(self, min_key: Optional[Any] = ..., max_key: Optional[Any] = ..., inclusive: Any = ..., reverse: bool = ...): ... + def bisect_left(self, value) -> int: ... + def bisect_right(self, value) -> int: ... + bisect: Any = ... + def bisect_key_left(self, key: Any) -> int: ... + def bisect_key_right(self, key: Any) -> int: ... + bisect_key: Any = ... + def count(self, value) -> int: ... + def copy(self): ... + __copy__: Any = ... + def index(self, value, start: int=..., stop: int=...) -> Any: ... + def __add__(self, other: Iterable[T]) -> Any: ... + __radd__: Any = ... + def __mul__(self, num: int) -> SortedKeyList[T]: ... + def __reduce__(self): ... +SortedListWithKey = SortedKeyList From 416a98d8dad7e9a0412d34dfb551c68049bc1d44 Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 9 Jan 2020 18:48:44 -0700 Subject: [PATCH 3/7] line too long --- sortedcontainers/sorteddict.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sortedcontainers/sorteddict.py b/sortedcontainers/sorteddict.py index 325ea6b7..a6d3634d 100644 --- a/sortedcontainers/sorteddict.py +++ b/sortedcontainers/sorteddict.py @@ -384,12 +384,18 @@ def method(self): method.__doc__ = message return property(method) - iteritems = __make_raise_attributeerror('iteritems', 'items') # type: ignore - iterkeys = __make_raise_attributeerror('iterkeys', 'keys') # type: ignore - itervalues = __make_raise_attributeerror('itervalues', 'values') # type: ignore - viewitems = __make_raise_attributeerror('viewitems', 'items') # type: ignore - viewkeys = __make_raise_attributeerror('viewkeys', 'keys') # type: ignore - viewvalues = __make_raise_attributeerror('viewvalues', 'values') # type: ignore + iteritems = \ + __make_raise_attributeerror('iteritems', 'items') # type: ignore + iterkeys = \ + __make_raise_attributeerror('iterkeys', 'keys') # type: ignore + itervalues = \ + __make_raise_attributeerror('itervalues', 'values') # type: ignore + viewitems = \ + __make_raise_attributeerror('viewitems', 'items') # type: ignore + viewkeys = \ + __make_raise_attributeerror('viewkeys', 'keys') # type: ignore + viewvalues = \ + __make_raise_attributeerror('viewvalues', 'values') # type: ignore class _NotGiven(object): From 63dc08a539f003588ceedeb6c8bd18af0e926553 Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 9 Jan 2020 20:39:24 -0700 Subject: [PATCH 4/7] sortedsets; better sortedlist --- .gitignore | 1 + sortedcontainers/sortedlist.pyi | 36 +++++++++--------- sortedcontainers/sortedset.pyi | 65 +++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 sortedcontainers/sortedset.pyi diff --git a/.gitignore b/.gitignore index 6a84a336..127d9b96 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # virutalenv directories /env*/ +/venv # test files/directories .coverage diff --git a/sortedcontainers/sortedlist.pyi b/sortedcontainers/sortedlist.pyi index ea1b0113..4b727c8a 100644 --- a/sortedcontainers/sortedlist.pyi +++ b/sortedcontainers/sortedlist.pyi @@ -4,7 +4,7 @@ from typing import Any, Callable, Iterable, MutableSequence, Optional, Tuple, Ty def recursive_repr(fillvalue: str = ...): ... T = TypeVar('T', covariant=True) -class SortedList(MutableSequence[T]): +class SortedList(MutableSequence[T], Generic[T]): DEFAULT_LOAD_FACTOR: int = ... def __init__(self, iterable: Iterable[T]=..., key: None=...) -> None: ... def __new__(cls: Any, iterable: Iterable[T]=..., key: Callable[[T], Any]=...) -> SortedList[T]: ... @@ -27,32 +27,32 @@ class SortedList(MutableSequence[T]): def __len__(self) -> int: ... def bisect_left(self, value) -> int: ... def bisect_right(self, value) -> int: ... - bisect: Any = ... + def bisect(self, value) -> int: ... def count(self, value) -> int: ... def copy(self) -> SortedList[T]: ... - __copy__: Any = ... + def __copy__(self) -> SortedList[T]: ... def append(self, value: Any) -> None: ... def extend(self, values: Any) -> None: ... def insert(self, index: Any, value: Any) -> None: ... def pop(self, index: int=...) -> T: ... def index(self, value: Any, start: int=..., stop: int=...) -> int: ... def __add__(self, other: SortedList[T]) -> SortedList[T]: ... - __radd__: Any = ... + def __radd__(self, other: SortedList[T]) -> SortedList[T]: ... def __iadd__(self, other: Iterable[T])-> SortedList[T]: ... def __mul__(self, num: int) -> SortedList[T]: ... - __rmul__: Any = ... + def __rmul__(self, num: int) -> SortedList[T]: ... def __imul__(self, num: int) -> SortedList[T]: ... - __eq__: Any = ... - __ne__: Any = ... - __lt__: Any = ... - __gt__: Any = ... - __le__: Any = ... - __ge__: Any = ... + def __eq__(self, other)-> bool: ... + def __ne__(self, other)-> bool: ... + def __lt__(self, other)-> bool: ... + def __gt__(self, other)-> bool: ... + def __le__(self, other)-> bool: ... + def __ge__(self, other)-> bool: ... def __reduce__(self): ... def identity(value: Any) -> T: ... -class SortedKeyList(SortedList[T]): +class SortedKeyList(SortedList[T], Generic[T]): def __init__(self, iterable: Iterable[T]=..., key: Callable[[T], Any]=...) -> None: ... def __new__(cls: Any, iterable: Iterable[T]=..., key: Callable[[T], Any]=...) -> Any: ... @property @@ -64,19 +64,19 @@ class SortedKeyList(SortedList[T]): def discard(self, value) -> None: ... def remove(self, value) -> None: ... def irange(self, minimum=..., maximum=..., inclusive: Tuple[bool, bool]=..., reverse: bool=...) -> Any: ... - def irange_key(self, min_key: Optional[Any] = ..., max_key: Optional[Any] = ..., inclusive: Any = ..., reverse: bool = ...): ... + def irange_key(self, min_key= ..., max_key = ..., inclusive: Tuple[bool, bool] = (True, True), reverse: bool = False): ... def bisect_left(self, value) -> int: ... def bisect_right(self, value) -> int: ... - bisect: Any = ... + def bisect(self, value) -> int: ... def bisect_key_left(self, key: Any) -> int: ... def bisect_key_right(self, key: Any) -> int: ... - bisect_key: Any = ... + def bisect_key(self, key: Any) -> int: ... def count(self, value) -> int: ... - def copy(self): ... - __copy__: Any = ... + def copy(self) -> SortedList[T]: ... + def __copy__(self) -> SortedList[T]: ... def index(self, value, start: int=..., stop: int=...) -> Any: ... def __add__(self, other: Iterable[T]) -> Any: ... - __radd__: Any = ... + def __radd__(self, other: Iterable[T]) -> Any: ... def __mul__(self, num: int) -> SortedKeyList[T]: ... def __reduce__(self): ... SortedListWithKey = SortedKeyList diff --git a/sortedcontainers/sortedset.pyi b/sortedcontainers/sortedset.pyi new file mode 100644 index 00000000..c92a7203 --- /dev/null +++ b/sortedcontainers/sortedset.pyi @@ -0,0 +1,65 @@ +from .sortedlist import SortedList as SortedList, recursive_repr as recursive_repr +from typing import MutableSet, Sequence, TypeVar, Callable, Generic, Iterable, Tuple, Iterator +from typing import Any, Optional + +_T_co = TypeVar('_T_co') +class SortedSet(MutableSet[_T_co], Sequence[_T_co], Generic[_T_co]): + def isdisjoint(self, s: Iterable[_T_co]) -> bool: ... + def issubset(self, s: Iterable[_T_co]) -> bool: ... + def issuperset(self, s: Iterable[_T_co]) -> bool: ... + def bisect_left(self, value) -> int: ... + def bisect(self, value) -> int: ... + def bisect_right(self, value) -> int: ... + def index(self, value: Any, start: int=..., stop: int=...) -> int: ... + def irange(self, minimum=..., maximum=..., inclusive: Tuple[bool, bool]=..., reverse: bool=...) -> Any: ... + def islice(self, start: int=..., stop: int=..., reverse: bool=...) -> Iterable[_T_co]: ... + def bisect_key_left(self, key: Any) -> int: ... + def bisect_key_right(self, key: Any) -> int: ... + def bisect_key(self, key: Any) -> int: ... + def irange_key(self, min_key= ..., max_key = ..., inclusive: Tuple[bool, bool] = (True, True), reverse: bool = False): ... + def __init__(self, iterable: Iterable[_T_co] = None, key: Callable[[_T_co], Any] = None) -> None: ... + @property + def key(self) -> Optional[Callable[[_T_co], Any]]: ... + def __contains__(self, value: Any) -> bool: ... + # fixme: weird "signature incompatible with Supertype 'Sequence'" warning from mypy + def __getitem__(self, index: int) -> _T_co: ... # type: ignore + def __delitem__(self, index: int) -> None: ... + def __eq__(self, other: Any)->bool: ... + def __ne__(self, other: Any)->bool: ... + def __lt__(self, other: Any)->bool: ... + def __gt__(self, other: Any)->bool: ... + def __le__(self, other: Any)->bool: ... + def __ge__(self, other: Any)->bool: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T_co]: ... + def __reversed__(self) -> Iterator[_T_co]: ... + def add(self, value: Any) -> None: ... + def clear(self) -> None: ... + def copy(self) -> SortedSet[_T_co]: ... + def __copy__(self) -> SortedSet[_T_co]: ... + def count(self, value: Any): ... + def discard(self, value: Any) -> None: ... + def pop(self, index: int = ...) -> _T_co: ... + def remove(self, value: Any) -> None: ... + # note: not necessarily Iterable[_T_co] + def difference(self, *iterables: Iterable)->SortedSet[_T_co]: ... + def __sub__(self, *iterables: Iterable)->SortedSet[_T_co]: ... + def difference_update(self, *iterables: Iterable)->SortedSet[_T_co]: ... + def __isub__(self, *iterables: Iterable)->SortedSet[_T_co]: ... + # note: not necessarily SortedSet[_T_co] + def intersection(self, *iterables: Iterable)->SortedSet: ... + def __and__(self, *iterables: Iterable)->SortedSet: ... + def __rand__(self, *iterables: Iterable)->SortedSet: ... + def intersection_update(self, *iterables: Iterable)->SortedSet: ... + def __iand__(self, *iterables: Iterable)->SortedSet: ... + def symmetric_difference(self, other: Iterable)->SortedSet: ... + def __xor__(self, other: Iterable)->SortedSet: ... + def __rxor__(self, other: Iterable)->SortedSet: ... + def symmetric_difference_update(self, other: Iterable)->SortedSet: ... + def __ixor__(self, other: Iterable)->SortedSet: ... + def union(self, *iterables: Iterable)->SortedSet: ... + def __or__(self, *iterables: Iterable)->SortedSet: ... + def __ror__(self, *iterables: Iterable)->SortedSet: ... + def update(self, *iterables: Iterable)->SortedSet: ... + def __ior__(self, *iterables: Iterable)->SortedSet: ... + def __reduce__(self): ... From da18424ca2fb7147143d43b3868862d6297556c0 Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 9 Jan 2020 21:09:32 -0700 Subject: [PATCH 5/7] typing backport for python3.4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4b9555a2..b4acf8db 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ def run_tests(self): zip_safe=False, tests_require=['tox'], cmdclass={'test': Tox}, - install_requires=[], + install_requires=["typing"], classifiers=( 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', From 4f78c747c5eb8d22fedd4ffbfc23269e9025ecc4 Mon Sep 17 00:00:00 2001 From: matt Date: Tue, 14 Jan 2020 12:09:15 -0700 Subject: [PATCH 6/7] remove typing, add set.pyi to data --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index b4acf8db..644fdc14 100644 --- a/setup.py +++ b/setup.py @@ -28,11 +28,11 @@ def run_tests(self): url='http://www.grantjenks.com/docs/sortedcontainers/', license='Apache 2.0', packages=['sortedcontainers'], - package_data={'sortedcontainers':["py.typed", "sortedlist.pyi"]}, + package_data={'sortedcontainers':["py.typed", "sortedlist.pyi", "sortedset.pyi"]}, zip_safe=False, tests_require=['tox'], cmdclass={'test': Tox}, - install_requires=["typing"], + install_requires=[], classifiers=( 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', From b3568358fd8b9491de4bb82ab49b9c94bfaf1499 Mon Sep 17 00:00:00 2001 From: matt Date: Tue, 14 Jan 2020 12:42:53 -0700 Subject: [PATCH 7/7] clean 2.7 3.4 tests --- sortedcontainers/sortedlist.py | 33 +++++++------------------------ sortedcontainers/sortedset.py | 16 +++------------ sortedcontainers/sortedset.pyi | 36 +++++++++++++++++----------------- tox.ini | 2 +- 4 files changed, 29 insertions(+), 58 deletions(-) diff --git a/sortedcontainers/sortedlist.py b/sortedcontainers/sortedlist.py index 8b5699db..7cb3b7ed 100644 --- a/sortedcontainers/sortedlist.py +++ b/sortedcontainers/sortedlist.py @@ -24,32 +24,13 @@ from math import log from operator import add, eq, ne, gt, ge, lt, le, iadd from textwrap import dedent - -############################################################################### -# BEGIN Python 2/3 Shims -############################################################################### - +from typing import MutableSequence, TypeVar, Generic, Sequence +from functools import wraps +from functools import reduce try: - from collections.abc import Sequence, MutableSequence + from _thread import get_ident except ImportError: - from collections import Sequence, MutableSequence - -from functools import wraps -from sys import hexversion - -if hexversion < 0x03000000: - from itertools import imap as map # pylint: disable=redefined-builtin - from itertools import izip as zip # pylint: disable=redefined-builtin - try: - from thread import get_ident - except ImportError: - from dummy_thread import get_ident -else: - from functools import reduce - try: - from _thread import get_ident - except ImportError: - from _dummy_thread import get_ident + from _dummy_thread import get_ident def recursive_repr(fillvalue='...'): @@ -81,8 +62,8 @@ def wrapper(self): # END Python 2/3 Shims ############################################################################### - -class SortedList(MutableSequence): +T = TypeVar('T', covariant=True) +class SortedList(MutableSequence[T], Generic[T]): """Sorted list is a sorted mutable sequence. Sorted list values are maintained in sorted order. diff --git a/sortedcontainers/sortedset.py b/sortedcontainers/sortedset.py index ff81f370..dd55291d 100644 --- a/sortedcontainers/sortedset.py +++ b/sortedcontainers/sortedset.py @@ -16,24 +16,14 @@ from itertools import chain from operator import eq, ne, gt, ge, lt, le from textwrap import dedent +from typing import TypeVar, Generic, Sequence, MutableSet, Set from .sortedlist import SortedList, recursive_repr -############################################################################### -# BEGIN Python 2/3 Shims -############################################################################### -try: - from collections.abc import MutableSet, Sequence, Set -except ImportError: - from collections import MutableSet, Sequence, Set +T = TypeVar('T') -############################################################################### -# END Python 2/3 Shims -############################################################################### - - -class SortedSet(MutableSet, Sequence): +class SortedSet(MutableSet[T], Sequence[T], Generic[T]): """Sorted set is a sorted mutable set. Sorted set values are maintained in sorted order. The design of sorted set diff --git a/sortedcontainers/sortedset.pyi b/sortedcontainers/sortedset.pyi index c92a7203..847b0625 100644 --- a/sortedcontainers/sortedset.pyi +++ b/sortedcontainers/sortedset.pyi @@ -2,27 +2,27 @@ from .sortedlist import SortedList as SortedList, recursive_repr as recursive_re from typing import MutableSet, Sequence, TypeVar, Callable, Generic, Iterable, Tuple, Iterator from typing import Any, Optional -_T_co = TypeVar('_T_co') -class SortedSet(MutableSet[_T_co], Sequence[_T_co], Generic[_T_co]): - def isdisjoint(self, s: Iterable[_T_co]) -> bool: ... - def issubset(self, s: Iterable[_T_co]) -> bool: ... - def issuperset(self, s: Iterable[_T_co]) -> bool: ... +T = TypeVar('T') +class SortedSet(MutableSet[T], Sequence[T], Generic[T]): + def isdisjoint(self, s: Iterable[T]) -> bool: ... + def issubset(self, s: Iterable[T]) -> bool: ... + def issuperset(self, s: Iterable[T]) -> bool: ... def bisect_left(self, value) -> int: ... def bisect(self, value) -> int: ... def bisect_right(self, value) -> int: ... def index(self, value: Any, start: int=..., stop: int=...) -> int: ... def irange(self, minimum=..., maximum=..., inclusive: Tuple[bool, bool]=..., reverse: bool=...) -> Any: ... - def islice(self, start: int=..., stop: int=..., reverse: bool=...) -> Iterable[_T_co]: ... + def islice(self, start: int=..., stop: int=..., reverse: bool=...) -> Iterable[T]: ... def bisect_key_left(self, key: Any) -> int: ... def bisect_key_right(self, key: Any) -> int: ... def bisect_key(self, key: Any) -> int: ... def irange_key(self, min_key= ..., max_key = ..., inclusive: Tuple[bool, bool] = (True, True), reverse: bool = False): ... - def __init__(self, iterable: Iterable[_T_co] = None, key: Callable[[_T_co], Any] = None) -> None: ... + def __init__(self, iterable: Iterable[T] = None, key: Callable[[T], Any] = None) -> None: ... @property - def key(self) -> Optional[Callable[[_T_co], Any]]: ... + def key(self) -> Optional[Callable[[T], Any]]: ... def __contains__(self, value: Any) -> bool: ... # fixme: weird "signature incompatible with Supertype 'Sequence'" warning from mypy - def __getitem__(self, index: int) -> _T_co: ... # type: ignore + def __getitem__(self, index: int) -> T: ... # type: ignore def __delitem__(self, index: int) -> None: ... def __eq__(self, other: Any)->bool: ... def __ne__(self, other: Any)->bool: ... @@ -31,21 +31,21 @@ class SortedSet(MutableSet[_T_co], Sequence[_T_co], Generic[_T_co]): def __le__(self, other: Any)->bool: ... def __ge__(self, other: Any)->bool: ... def __len__(self) -> int: ... - def __iter__(self) -> Iterator[_T_co]: ... - def __reversed__(self) -> Iterator[_T_co]: ... + def __iter__(self) -> Iterator[T]: ... + def __reversed__(self) -> Iterator[T]: ... def add(self, value: Any) -> None: ... def clear(self) -> None: ... - def copy(self) -> SortedSet[_T_co]: ... - def __copy__(self) -> SortedSet[_T_co]: ... + def copy(self) -> SortedSet[T]: ... + def __copy__(self) -> SortedSet[T]: ... def count(self, value: Any): ... def discard(self, value: Any) -> None: ... - def pop(self, index: int = ...) -> _T_co: ... + def pop(self, index: int = ...) -> T: ... def remove(self, value: Any) -> None: ... # note: not necessarily Iterable[_T_co] - def difference(self, *iterables: Iterable)->SortedSet[_T_co]: ... - def __sub__(self, *iterables: Iterable)->SortedSet[_T_co]: ... - def difference_update(self, *iterables: Iterable)->SortedSet[_T_co]: ... - def __isub__(self, *iterables: Iterable)->SortedSet[_T_co]: ... + def difference(self, *iterables: Iterable)->SortedSet[T]: ... + def __sub__(self, *iterables: Iterable)->SortedSet[T]: ... + def difference_update(self, *iterables: Iterable)->SortedSet[T]: ... + def __isub__(self, *iterables: Iterable)->SortedSet[T]: ... # note: not necessarily SortedSet[_T_co] def intersection(self, *iterables: Iterable)->SortedSet: ... def __and__(self, *iterables: Iterable)->SortedSet: ... diff --git a/tox.ini b/tox.ini index dc46e84d..a5722f06 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py27,py34,py35,py36,py37,pypy,pypy3,lint +envlist=py35,py36,py37,pypy3,lint skip_missing_interpreters=True [testenv]