diff -r ce637db93b36 pypy/interpreter/function.py --- a/pypy/interpreter/function.py Mon Dec 03 17:42:13 2018 +0100 +++ b/pypy/interpreter/function.py Mon Dec 03 22:12:07 2018 +0200 @@ -39,8 +39,6 @@ 'qualname?', 'w_kw_defs?'] - w_kw_defs = None - def __init__(self, space, code, w_globals=None, defs_w=[], kw_defs_w=None, closure=None, w_ann=None, forcename=None, qualname=None): self.space = space @@ -54,6 +52,7 @@ self.w_func_dict = None # filled out below if needed self.w_module = None self.w_ann = w_ann + self.w_kw_defs = None # if kw_defs_w is not None: self.init_kwdefaults_dict(kw_defs_w) @@ -406,10 +405,22 @@ def init_kwdefaults_dict(self, kw_defs_w): # use the moduledict logic to get normally-constant entries space = self.space - w_dict = space.newdict(module=True) - for w_name, w_value in kw_defs_w: - space.setitem(w_dict, w_name, w_value) - self.w_kw_defs = w_dict + if hasattr(space, 'w_dict'): # normal path + w_dict = space.newdict(module=True) + for w_name, w_value in kw_defs_w: + space.setitem(w_dict, w_name, w_value) + self.w_kw_defs = w_dict + else: + del self.w_kw_defs # delayed path during initialization + self._saved_kw_defs_w = kw_defs_w + + def __getattr__(self, attr): + if attr == 'w_kw_defs' and hasattr(self, '_saved_kw_defs_w'): + assert hasattr(self.space, 'w_dict') + self.init_kwdefaults_dict(self._saved_kw_defs_w) + del self._saved_kw_defs_w + return self.w_kw_defs + raise AttributeError def fget_func_doc(self, space): if self.w_doc is None: diff -r ce637db93b36 pypy/objspace/std/intobject.py --- a/pypy/objspace/std/intobject.py Mon Dec 03 17:42:13 2018 +0100 +++ b/pypy/objspace/std/intobject.py Mon Dec 03 22:12:07 2018 +0200 @@ -98,7 +98,7 @@ return w_obj @unwrap_spec(length=int, byteorder='text', signed=bool) - def descr_to_bytes(self, space, length, byteorder, signed=False): + def descr_to_bytes(self, space, length, byteorder, __kwonly__, signed=False): """to_bytes(...) int.to_bytes(length, byteorder, *, signed=False) -> bytes diff -r ce637db93b36 pypy/objspace/std/test/test_longobject.py --- a/pypy/objspace/std/test/test_longobject.py Mon Dec 03 17:42:13 2018 +0100 +++ b/pypy/objspace/std/test/test_longobject.py Mon Dec 03 22:12:07 2018 +0200 @@ -379,6 +379,7 @@ raises(OverflowError, (-5).to_bytes, 1, 'big') raises(ValueError, (-5).to_bytes, 1, 'foo') assert 65535 .to_bytes(length=2, byteorder='big') == b'\xff\xff' + raises(TypeError, 65535 .to_bytes, 2, 'big', False) def test_negative_zero(self): x = eval("-self._long(0)")