Skip to content

Rely on Py3 kwonly args to make the signature of Pipeline explicit. #42

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions slicerator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import collections.abc
import itertools
from functools import wraps
Expand Down Expand Up @@ -177,8 +174,6 @@ def from_class(cls, some_class, propagate_attrs=None):
class SliceratorSubclass(some_class):
_slicerator_flag = True
_get = some_class.__getitem__
if hasattr(some_class, '__doc__'):
__doc__ = some_class.__doc__ # for Python 2, do it here

def __getitem__(self, i):
"""Getitem supports repeated slicing via Slicerator objects."""
Expand All @@ -188,7 +183,7 @@ def __getitem__(self, i):
else:
return cls(self, indices, new_length, propagate_attrs)

for name in ['__name__', '__module__', '__repr__']:
for name in ['__name__', '__module__', '__repr__', '__doc__']:
try:
setattr(SliceratorSubclass, name, getattr(some_class, name))
except AttributeError:
Expand Down Expand Up @@ -361,7 +356,8 @@ def _index_generator(new_indices, old_indices):


class Pipeline(object):
def __init__(self, proc_func, *ancestors, **kwargs):
def __init__(self, proc_func, *ancestors,
propagate_attrs=None, propagate_how='first'):
"""A class to support lazy function evaluation on an iterable.

When a ``Pipeline`` object is indexed, it returns an element of its
Expand Down Expand Up @@ -401,15 +397,6 @@ def __init__(self, proc_func, *ancestors, **kwargs):
--------
pipeline
"""
# Python 2 does not allow default arguments in combination with
# variable arguments; work around that
propagate_attrs = kwargs.pop('propagate_attrs', None)
propagate_how = kwargs.pop('propagate_how', 'first')
if kwargs:
# There are some left. This is an error.
raise TypeError("Unexpected keyword argument '{}'.".format(
next(iter(kwargs))))

# Only accept ancestors of the same length are accepted
self._len = len(ancestors[0])
if not all(len(a) == self._len for a in ancestors):
Expand Down