1- import inspect
2- import sys
3- from functools import partial
4- from importlib import import_module
5- from operator import attrgetter
6- from types import MethodType
7- from cytoolz.utils import no_default
8- import cytoolz._signatures as _sigs
9-
10- from toolz.functoolz import (InstanceProperty, instanceproperty, is_arity,
11- num_required_args, has_varargs, has_keywords,
12- is_valid_args, is_partial_args)
13-
141cimport cython
152from cpython.dict cimport PyDict_Merge, PyDict_New
163from cpython.object cimport (PyCallable_Check, PyObject_Call, PyObject_CallObject,
@@ -20,6 +7,48 @@ from cpython.sequence cimport PySequence_Concat
207from cpython.set cimport PyFrozenSet_New
218from cpython.tuple cimport PyTuple_Check, PyTuple_GET_SIZE
229
10+ import functools
11+ import importlib
12+ import inspect
13+ import operator
14+ import types
15+ from toolz import functoolz as functoolz_py
16+
17+ from cytools import _signatures
18+ from cytoolz import utils
19+
20+ # cdef constants to eliminate global lookups
21+ cdef object partial = functools.partial
22+ del functools
23+
24+ cdef object import_module = importlib.import_module
25+ del importlib
26+
27+ cdef object signature = inspect.signature
28+ del inspect
29+
30+ cdef object attrgetter = operator.attrgetter
31+ del operator
32+
33+ cdef object MethodType = types.MethodType
34+ del types
35+
36+ cdef object InstanceProperty = functoolz_py.InstanceProperty
37+ cdef object instanceproperty = functoolz_py.instanceproperty
38+ cdef object is_arity = functoolz_py.is_arity
39+ cdef object num_required_args = functoolz_py.num_required_args
40+ cdef object has_varargs = functoolz_py.has_varargs
41+ cdef object has_keywords = functoolz_py.has_keywords
42+ cdef object is_valid_args = functoolz_py.is_valid_args
43+ cdef object is_partial_args = functoolz_py.is_partial_args
44+ del functoolz_py
45+
46+ cdef object no_default = utils.no_default
47+ del utils
48+
49+ cdef object signature_or_spec = _signatures.signature_or_spec
50+ del _signatures
51+
2352
2453__all__ = [' identity' , ' thread_first' , ' thread_last' , ' memoize' , ' compose' , ' compose_left' ,
2554 ' pipe' , ' complement' , ' juxt' , ' do' , ' curry' , ' memoize' , ' flip' ,
@@ -289,7 +318,7 @@ cdef class curry:
289318 # kwargs = dict(self.keywords, **kwargs)
290319
291320 if self ._sigspec is None :
292- sigspec = self ._sigspec = _sigs. signature_or_spec(func)
321+ sigspec = self ._sigspec = signature_or_spec(func)
293322 self ._has_unknown_args = has_varargs(func, sigspec) is not False
294323 else :
295324 sigspec = self ._sigspec
@@ -330,7 +359,7 @@ cdef class curry:
330359
331360 property __signature__ :
332361 def __get__ (self ):
333- sig = inspect. signature(self .func)
362+ sig = signature(self .func)
334363 args = self .args or ()
335364 keywords = self .keywords or {}
336365 if is_partial_args(self .func, args, keywords, sig) is False :
@@ -558,8 +587,8 @@ cdef class Compose:
558587
559588 property __signature__ :
560589 def __get__ (self ):
561- base = inspect. signature(self .first)
562- last = inspect. signature(self .funcs[- 1 ])
590+ base = signature(self .first)
591+ last = signature(self .funcs[- 1 ])
563592 return base.replace(return_annotation = last.return_annotation)
564593
565594 property __name__ :
0 commit comments