return new code object with modified attributes.
if rec-cursive is true then dive into code
objects contained in co_consts.
def new(self, rec=False, **kwargs):
origin: code.Code
where:
exceptions that might appear during execution:
function source:
def new(self, rec=False, **kwargs):
""" return new code object with modified attributes.
if rec-cursive is true then dive into code
objects contained in co_consts.
"""
names = [x for x in dir(self.raw) if x[:3] == 'co_']
for name in kwargs:
if name not in names:
raise TypeError("unknown code attribute: %r" %(name, ))
if rec:
newconstlist = []
co = self.raw
cotype = type(co)
for c in co.co_consts:
if isinstance(c, cotype):
c = self.__class__(c).new(rec=True, **kwargs)
newconstlist.append(c)
return self.new(rec=False, co_consts=tuple(newconstlist), **kwargs)
for name in names:
if name not in kwargs:
kwargs[name] = getattr(self.raw, name)
return py.std.new.code(
kwargs['co_argcount'],
kwargs['co_nlocals'],
kwargs['co_stacksize'],
kwargs['co_flags'],
kwargs['co_code'],
kwargs['co_consts'],
kwargs['co_names'],
kwargs['co_varnames'],
kwargs['co_filename'],
kwargs['co_name'],
kwargs['co_firstlineno'],
kwargs['co_lnotab'],
kwargs['co_freevars'],
kwargs['co_cellvars'],
)
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in None</home/johnny/projects/merlinux/py/dist/py/test/raises.py:20>
called in /home/johnny/projects/merlinux/py/dist/py/code/source.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/source.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/source.py
called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/source.py
called in /home/johnny/projects/merlinux/py/dist/py/code/source.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py
called in /home/johnny/projects/merlinux/py/dist/py/code/code.py