Skip to content

Commit bf85c5c

Browse files
committed
More shit
1 parent 4a83132 commit bf85c5c

File tree

17 files changed

+132
-245
lines changed

17 files changed

+132
-245
lines changed

docs/topics/cute-inspect.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

python_toolbox/caching/cached_property.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
See its documentation for more details.
88
'''
99

10-
from python_toolbox import decorator_tools
1110
from python_toolbox import misc_tools
11+
from python_toolbox.third_party.decorator import decorator
1212

1313

1414
class CachedProperty(misc_tools.OwnNameDiscoveringDescriptor):
@@ -73,7 +73,7 @@ def __call__(self, method_function):
7373
def inner(same_method_function, self_obj, *args, **kwargs):
7474
with getattr(self_obj, self.get_our_name(self_obj)):
7575
return method_function(self_obj, *args, **kwargs)
76-
return decorator_tools.decorator(inner, method_function)
76+
return decorator(inner, method_function)
7777

7878

7979
def __repr__(self):

python_toolbox/caching/decorators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from python_toolbox import binary_search
1515
from python_toolbox import decorator_tools
1616
from python_toolbox.sleek_reffing import SleekCallArgs
17+
from python_toolbox.third_party.decorator import decorator as decorator_
1718

1819
infinity = float('inf')
1920

@@ -158,7 +159,7 @@ def cached(function, *args, **kwargs):
158159
return value
159160

160161

161-
result = decorator_tools.decorator(cached, function)
162+
result = decorator_(cached, function)
162163

163164
def cache_clear(key=CLEAR_ENTIRE_CACHE):
164165
if key is CLEAR_ENTIRE_CACHE:

python_toolbox/context_management/mixins/decorating_context_manager_mixin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2009-2017 Ram Rachum.
22
# This program is distributed under the MIT license.
33

4-
from python_toolbox import decorator_tools
4+
from python_toolbox.third_party.decorator import decorator
55

66

77
class _DecoratingContextManagerMixin:
@@ -24,4 +24,4 @@ def __call__(self, function):
2424
def inner(function_, *args, **kwargs):
2525
with self:
2626
return function_(*args, **kwargs)
27-
return decorator_tools.decorator(inner, function)
27+
return decorator(inner, function)

python_toolbox/cute_inspect/__init__.py

Lines changed: 0 additions & 112 deletions
This file was deleted.

python_toolbox/cute_profile/cute_profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import marshal
1212

1313
from python_toolbox import misc_tools
14-
from python_toolbox import decorator_tools
14+
from python_toolbox.third_party.decorator import decorator
1515

1616
from . import base_profile
1717
from . import profile_handling
@@ -120,7 +120,7 @@ def inner(function_, *args, **kwargs):
120120

121121
return decorated_function.original_function(*args, **kwargs)
122122

123-
decorated_function = decorator_tools.decorator(inner, function)
123+
decorated_function = decorator(inner, function)
124124

125125
decorated_function.original_function = function
126126
decorated_function.profiling_on = None

python_toolbox/cute_testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import nose
77
import sys
8+
import inspect
89

910
from python_toolbox.third_party import unittest2
1011

11-
from python_toolbox import cute_inspect
1212
from python_toolbox import context_management
1313
from python_toolbox.exceptions import CuteException
1414
from python_toolbox import logic_tools
@@ -109,7 +109,7 @@ def manage_context(self):
109109

110110
def assert_same_signature(*callables):
111111
'''Assert that all the `callables` have the same function signature.'''
112-
arg_specs = [cute_inspect.getargspec(callable_) for callable_ in callables]
112+
arg_specs = [inspect.getfullargspec(callable_) for callable_ in callables]
113113
if not logic_tools.all_equivalent(arg_specs, assume_transitive=False):
114114
raise Failure('Not all the callables have the same signature.')
115115

python_toolbox/decorator_tools.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,6 @@
99

1010
from python_toolbox.third_party import decorator as michele_decorator_module
1111

12-
def decorator(caller, func=None):
13-
'''
14-
Create a decorator.
15-
16-
`decorator(caller)` converts a caller function into a decorator;
17-
`decorator(caller, func)` decorates a function using a caller.
18-
'''
19-
if func is not None: # returns a decorated function
20-
evaldict = func.__globals__.copy()
21-
evaldict['_call_'] = caller
22-
evaldict['_func_'] = func
23-
result = michele_decorator_module.FunctionMaker.create(
24-
func, "return _call_(_func_, %(shortsignature)s)",
25-
evaldict, undecorated=func)
26-
result.__wrapped__ = func
27-
return result
28-
else: # returns a decorator
29-
if isinstance(caller, functools.partial):
30-
return functools.partial(decorator, caller)
31-
# otherwise assume caller is a function
32-
first = inspect.getargspec(caller)[0][0] # first arg
33-
evaldict = caller.__globals__.copy()
34-
evaldict['_call_'] = caller
35-
evaldict['decorator'] = decorator
36-
return michele_decorator_module.FunctionMaker.create(
37-
'%s(%s)' % (caller.__name__, first),
38-
'return decorator(_call_, %s)' % first,
39-
evaldict, undecorated=caller,
40-
doc=caller.__doc__, module=caller.__module__)
41-
4212

4313
def helpful_decorator_builder(decorator_builder):
4414
'''
@@ -89,4 +59,4 @@ def inner(same_decorator_builder, *args, **kwargs):
8959
else:
9060
return decorator_builder(*args, **kwargs)
9161

92-
return decorator(inner, decorator_builder)
62+
return functools.wraps(inner)(decorator_builder)

python_toolbox/introspection_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
'''Defines various introspection tools, similar to the stdlib's `inspect`.'''
55

6-
from python_toolbox import cute_inspect
6+
import inspect
77

88
from python_toolbox.nifty_collections import OrderedDict
99

@@ -19,7 +19,7 @@ def get_default_args_dict(function):
1919
OrderedDict([('c', 1), ('d', 'meow')])
2020
2121
'''
22-
arg_spec = cute_inspect.getargspec(function)
22+
arg_spec = inspect.getfullargspec(function)
2323
(s_args, s_star_args, s_star_kwargs, s_defaults) = arg_spec
2424

2525
# `getargspec` has a weird policy, when inspecting a function with no

python_toolbox/monkeypatching_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def change_defaults(function=None, new_defaults={}):
105105
be changed.
106106
'''
107107
def change_defaults_(function_, new_defaults_):
108-
signature = inspect.Signature.from_function(function_)
108+
signature = inspect.Signature.from_callable(function_)
109109
defaults = list(function_.__defaults__ or ())
110110
kwdefaults = function_.__kwdefaults__ or {}
111111
defaultful_parameters = dict_tools.filter_items(

0 commit comments

Comments
 (0)