mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-09 08:00:34 +03:00
Convert closure to functools.partial, to promote pickling
This commit is contained in:
parent
32a8564c79
commit
9baa8fe7ec
|
@ -15,6 +15,7 @@ import io
|
||||||
import dill
|
import dill
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from thinc.neural._classes.model import Model
|
from thinc.neural._classes.model import Model
|
||||||
|
import functools
|
||||||
|
|
||||||
import msgpack
|
import msgpack
|
||||||
import msgpack_numpy
|
import msgpack_numpy
|
||||||
|
@ -336,12 +337,16 @@ def add_lookups(default_func, *lookups):
|
||||||
*lookups (dict): Lookup dictionary mapping string to attribute value.
|
*lookups (dict): Lookup dictionary mapping string to attribute value.
|
||||||
RETURNS (callable): Lexical attribute getter.
|
RETURNS (callable): Lexical attribute getter.
|
||||||
"""
|
"""
|
||||||
def get_attr(string):
|
# This is implemented as functools.partial instead of a closure, to allow
|
||||||
for lookup in lookups:
|
# pickle to work.
|
||||||
if string in lookup:
|
return functools.partial(_get_attr_unless_lookup, default_func, lookups)
|
||||||
return lookup[string]
|
|
||||||
return default_func(string)
|
|
||||||
return get_attr
|
def _get_attr_unless_lookup(default_func, lookups, string):
|
||||||
|
for lookup in lookups:
|
||||||
|
if string in lookup:
|
||||||
|
return lookup[string]
|
||||||
|
return default_func(string)
|
||||||
|
|
||||||
|
|
||||||
def update_exc(base_exceptions, *addition_dicts):
|
def update_exc(base_exceptions, *addition_dicts):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user