mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-22 05:11:25 +08:00
Add sets and iterable/iterator
This commit is contained in:
@@ -7,7 +7,19 @@ from collections import abc
|
|||||||
|
|
||||||
|
|
||||||
def factory(typing_name, indextype):
|
def factory(typing_name, indextype):
|
||||||
class Sequence(abc.Sequence):
|
class Iterable(abc.Iterable):
|
||||||
|
def __iter__(self):
|
||||||
|
yield indextype()
|
||||||
|
|
||||||
|
class Iterator(Iterable, abc.Iterator):
|
||||||
|
def next(self):
|
||||||
|
""" needed for python 2 """
|
||||||
|
return self.__next__()
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
return indextype()
|
||||||
|
|
||||||
|
class Sequence(Iterable, abc.Sequence):
|
||||||
def __getitem__(self, index: int):
|
def __getitem__(self, index: int):
|
||||||
return indextype()
|
return indextype()
|
||||||
|
|
||||||
@@ -15,12 +27,29 @@ def factory(typing_name, indextype):
|
|||||||
def __setitem__(self, index: int, value: indextype):
|
def __setitem__(self, index: int, value: indextype):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __delitem__(self, index: int, value: indextype):
|
||||||
|
pass
|
||||||
|
|
||||||
class List(MutableSequence, list):
|
class List(MutableSequence, list):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class AbstractSet(Iterable, abc.Set):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class MutableSet(AbstractSet, abc.MutableSet):
|
||||||
|
def add(item: indextype):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def discard(item: indextype):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
dct = {
|
dct = {
|
||||||
"Sequence": Sequence,
|
"Sequence": Sequence,
|
||||||
"MutableSequence": MutableSequence,
|
"MutableSequence": MutableSequence,
|
||||||
"List": List,
|
"List": List,
|
||||||
|
"Iterable": Iterable,
|
||||||
|
"Iterator": Iterator,
|
||||||
|
"AbstractSet": AbstractSet,
|
||||||
|
"MutableSet": MutableSet,
|
||||||
}
|
}
|
||||||
return dct[typing_name]
|
return dct[typing_name]
|
||||||
|
|||||||
@@ -192,3 +192,35 @@ def we_can_has_sequence(
|
|||||||
u.a
|
u.a
|
||||||
#? float()
|
#? float()
|
||||||
u[1]
|
u[1]
|
||||||
|
|
||||||
|
def iterators(
|
||||||
|
ps: typing.Iterable[int],
|
||||||
|
qs: typing.Iterator[str],
|
||||||
|
rs: typing.Sequence["B"],
|
||||||
|
ts: typing.AbstractSet["float"]):
|
||||||
|
for p in ps:
|
||||||
|
#? int()
|
||||||
|
p
|
||||||
|
#?
|
||||||
|
next(ps)
|
||||||
|
for q in qs:
|
||||||
|
#? str()
|
||||||
|
q
|
||||||
|
#? str()
|
||||||
|
next(qs)
|
||||||
|
for r in rs:
|
||||||
|
#? B()
|
||||||
|
r
|
||||||
|
#?
|
||||||
|
next(rs)
|
||||||
|
for t in ts:
|
||||||
|
#? float()
|
||||||
|
t
|
||||||
|
|
||||||
|
def sets(
|
||||||
|
p: typing.AbstractSet[int],
|
||||||
|
q: typing.MutableSet[float]):
|
||||||
|
#? []
|
||||||
|
p.a
|
||||||
|
#? ["add"]
|
||||||
|
q.a
|
||||||
|
|||||||
Reference in New Issue
Block a user