Partially apply doc/span/token into method

We want methods to act like they're "bound" to the object, so that you can make your method conditional on the `doc`, `span` or `token` instance --- like, well, a method. We therefore partially apply the function, which works like this:

```
def partial(unbound_method, constant_arg):
    def bound_method(*args, **kwargs):
        return unbound_method(constant_arg, *args, **kwargs)
    return bound_method
This commit is contained in:
Matthew Honnibal 2017-10-10 02:21:28 +02:00 committed by GitHub
parent de374dc72a
commit 51d18937af

View File

@ -1,3 +1,5 @@
import functools
class Underscore(object):
doc_extensions = {}
span_extensions = {}
@ -22,7 +24,7 @@ class Underscore(object):
if getter is not None:
return getter(self._obj)
elif method is not None:
return method
return functools.partial(method, self._obj)
else:
return self._doc.user_data.get(self._get_key(name), default)