Skip to content
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

Update to latest toolz: make juxt a class with .funcs #170

Merged
merged 6 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build wheels

on:
# pull_request: # Uncomment to debug wheel building in a PR
push:
branches:
- master
Expand All @@ -23,10 +24,13 @@ jobs:
# # Archs: https://cibuildwheel.readthedocs.io/en/stable/options/#archs
# # This probably isn't the preferred way to do things :shrug:
#
# # PyPy may have issues. Intermittent failures have been seen on:
# # pp37-manylinux_aarch64 pp38-win_amd64
#
# pys = ['cp36', 'cp37', 'cp38', 'cp39', 'cp310']
# pys_arm = ['cp38', 'cp39', 'cp310']
# pypys = ['pp37', 'pp38', 'pp39']
# SKIP = {"pp37-manylinux_aarch64"}
# SKIP = set() # {"pp37-manylinux_aarch64", "pp38-win_amd64"}
# combos = []
#
# # Linux
Expand Down Expand Up @@ -120,8 +124,8 @@ jobs:
- {"os": "ubuntu", "build": "cp310-musllinux_ppc64le", "arch": "ppc64le"}
- {"os": "ubuntu", "build": "cp310-musllinux_s390x", "arch": "s390x"}
- {"os": "ubuntu", "build": "cp310-musllinux_x86_64", "arch": "x86_64"}
# Segfault in test_dicttoolz.py:test_merge_with
# - {"os": "ubuntu", "build": "pp37-manylinux_aarch64", "arch": "aarch64"}
# Intermittent segfault on pp37-manylinux_aarch64 in test_dicttoolz.py:test_merge_with
- {"os": "ubuntu", "build": "pp37-manylinux_aarch64", "arch": "aarch64"}
- {"os": "ubuntu", "build": "pp37-manylinux_i686", "arch": "i686"}
- {"os": "ubuntu", "build": "pp37-manylinux_x86_64", "arch": "x86_64"}
- {"os": "ubuntu", "build": "pp38-manylinux_aarch64", "arch": "aarch64"}
Expand Down
2 changes: 1 addition & 1 deletion cytoolz/__init__.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from cytoolz.itertoolz cimport (


from cytoolz.functoolz cimport (
c_compose, c_juxt, memoize, c_pipe, c_thread_first, c_thread_last,
c_compose, memoize, c_pipe, c_thread_first, c_thread_last,
complement, curry, do, identity, excepts, flip)


Expand Down
7 changes: 6 additions & 1 deletion cytoolz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@

functoolz._sigs.update_signature_registry()

from ._version import __version__, __toolz_version__
# What version of toolz does cytoolz implement?
__toolz_version__ = '0.12.0'

from ._version import get_versions

__version__ = get_versions()['version']
del get_versions
7 changes: 0 additions & 7 deletions cytoolz/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
import functools


# What version of toolz does cytoolz implement? Placed here compatibility.
__toolz_version__ = '0.12.0'


def get_keywords():
"""Get the keywords needed to look up the version information."""
# these strings will be replaced by git during git-archive.
Expand Down Expand Up @@ -659,6 +655,3 @@ def get_versions():
return {"version": "0+unknown", "full-revisionid": None,
"dirty": None,
"error": "unable to compute version", "date": None}


__version__ = get_versions()['version']
5 changes: 1 addition & 4 deletions cytoolz/functoolz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ cdef class complement:
cdef object func


cdef class _juxt_inner:
cdef class juxt:
cdef public tuple funcs


cdef object c_juxt(object funcs)


cpdef object do(object func, object x)


Expand Down
42 changes: 18 additions & 24 deletions cytoolz/functoolz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -691,26 +691,9 @@ cdef class complement:
return (complement, (self.func,))


cdef class _juxt_inner:
def __cinit__(self, funcs):
self.funcs = tuple(funcs)

def __call__(self, *args, **kwargs):
if kwargs:
return tuple(PyObject_Call(func, args, kwargs) for func in self.funcs)
else:
return tuple(PyObject_CallObject(func, args) for func in self.funcs)
cdef class juxt:
""" juxt(self, *funcs)

def __reduce__(self):
return (_juxt_inner, (self.funcs,))


cdef object c_juxt(object funcs):
return _juxt_inner(funcs)


def juxt(*funcs):
"""
Creates a function that calls several functions with the same arguments

Takes several functions and returns a function that applies its arguments
Expand All @@ -726,9 +709,19 @@ def juxt(*funcs):
>>> juxt([inc, double])(10)
(11, 20)
"""
if len(funcs) == 1 and not PyCallable_Check(funcs[0]):
funcs = funcs[0]
return c_juxt(funcs)
def __cinit__(self, *funcs):
if len(funcs) == 1 and not PyCallable_Check(funcs[0]):
funcs = funcs[0]
self.funcs = tuple(funcs)

def __call__(self, *args, **kwargs):
if kwargs:
return tuple(PyObject_Call(func, args, kwargs) for func in self.funcs)
else:
return tuple(PyObject_CallObject(func, args) for func in self.funcs)

def __reduce__(self):
return (juxt, (self.funcs,))


cpdef object do(object func, object x):
Expand Down Expand Up @@ -796,7 +789,8 @@ cpdef object return_none(object exc):


cdef class excepts:
"""
""" excepts(self, exc, func, handler=return_none)

A wrapper around a function to catch exceptions and
dispatch to a handler.

Expand Down Expand Up @@ -825,7 +819,7 @@ cdef class excepts:
1
"""

def __init__(self, exc, func, handler=return_none):
def __cinit__(self, exc, func, handler=return_none):
self.exc = exc
self.func = func
self.handler = handler
Expand Down