forked from VimPlug/jedi
52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
"""
|
|
This module is not intended to be used in jedi, rather it will be fed to the
|
|
jedi-parser to replace classes in the typing module
|
|
"""
|
|
|
|
try:
|
|
from collections import abc
|
|
except ImportError:
|
|
# python 2
|
|
import collections as abc
|
|
|
|
|
|
def factory(typing_name, indextype):
|
|
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):
|
|
return indextype()
|
|
|
|
class MutableSequence(Sequence, abc.MutableSequence):
|
|
pass
|
|
|
|
class List(MutableSequence, list):
|
|
pass
|
|
|
|
class AbstractSet(Iterable, abc.Set):
|
|
pass
|
|
|
|
class MutableSet(AbstractSet, abc.MutableSet):
|
|
pass
|
|
|
|
dct = {
|
|
"Sequence": Sequence,
|
|
"MutableSequence": MutableSequence,
|
|
"List": List,
|
|
"Iterable": Iterable,
|
|
"Iterator": Iterator,
|
|
"AbstractSet": AbstractSet,
|
|
"MutableSet": MutableSet,
|
|
}
|
|
return dct[typing_name]
|