From 5a8b9541a7da4b5a75e74da6e22d74aa50e9f65a Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 12 Sep 2017 23:18:32 +0200 Subject: [PATCH] Add operator.itemgetter support for Python <= 3.3. Also fixes namedtuple support for these versions. --- jedi/evaluate/compiled/fake/operator.pym | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 jedi/evaluate/compiled/fake/operator.pym diff --git a/jedi/evaluate/compiled/fake/operator.pym b/jedi/evaluate/compiled/fake/operator.pym new file mode 100644 index 00000000..d40d4681 --- /dev/null +++ b/jedi/evaluate/compiled/fake/operator.pym @@ -0,0 +1,33 @@ +# Just copied this code from Python 3.6. + +class itemgetter: + """ + Return a callable object that fetches the given item(s) from its operand. + After f = itemgetter(2), the call f(r) returns r[2]. + After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3]) + """ + __slots__ = ('_items', '_call') + + def __init__(self, item, *items): + if not items: + self._items = (item,) + def func(obj): + return obj[item] + self._call = func + else: + self._items = items = (item,) + items + def func(obj): + return tuple(obj[i] for i in items) + self._call = func + + def __call__(self, obj): + return self._call(obj) + + def __repr__(self): + return '%s.%s(%s)' % (self.__class__.__module__, + self.__class__.__name__, + ', '.join(map(repr, self._items))) + + def __reduce__(self): + return self.__class__, self._items +