Author: Philip Jenvey <pjen...@underboss.org> Branch: stdlib-2.7.12 Changeset: r87531:a4a7312e476a Date: 2016-10-02 16:10 -0700 http://bitbucket.org/pypy/pypy/changeset/a4a7312e476a/
Log: tigthen partial.__setstate__ diff --git a/lib_pypy/_functools.py b/lib_pypy/_functools.py --- a/lib_pypy/_functools.py +++ b/lib_pypy/_functools.py @@ -8,6 +8,9 @@ partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords. """ + + __slots__ = ('_func', '_args', '_keywords', '__dict__') + def __init__(*args, **keywords): if len(args) < 2: raise TypeError('__init__() takes at least 2 arguments (%d given)' @@ -50,9 +53,25 @@ (self._func, self._args, self._keywords, d)) def __setstate__(self, state): + if not isinstance(state, tuple) or len(state) != 4: + raise TypeError("invalid partial state") + func, args, keywords, d = state - if d is not None: + + if (not callable(func) or not isinstance(args, tuple) or + (keywords != None and not isinstance(keywords, dict))): + raise TypeError("invalid partial state") + + self._func = func + self._args = tuple(args) + + if keywords is None: + keywords = {} + elif type(keywords) is not dict: + keywords = dict(keywords) + self._keywords = keywords + + if d is None: + self.__dict__.clear() + else: self.__dict__.update(d) - self._func = func - self._args = args - self._keywords = keywords _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit