TypeError on CodeType creation in Python 3

I'm trying to create a new CodeType, the following code runs just fine in Python 2.7, but in Python 3.2 I get an error:

def newCode(co_argcount = 0, co_nlocals = 0, co_stacksize = 0, co_flags = 0x0000,
            co_code = bytes(), co_consts = (), co_names = (), co_varnames = (),
            filename = "<string>", name = "", firstlineno = 0, co_lnotab = bytes(),
            co_freevars = (), co_cellvars = ()):
    """wrapper for CodeType so that we can remember the synatax"""
    return types.CodeType(co_argcount, co_nlocals, co_stacksize,
                          co_flags, co_code, co_consts, co_names, co_varnames,
                          filename, name, firstlineno, co_lnotab, co_freevars, co_cellvars)


return newCode(co_code = code, co_stacksize = size, co_consts = consts)

The debug line proves that I'm sending in an int as co_stacksize...what changed in Python 3 to make this not work?

Edit: Here's the error (don't know why I forgot that before):

TypeError: an integer is required


On Python 3, the second argument to CodeType is the number of keyword-only arguments, co_kwonlyargcount. It's an addition, so all the later arguments will be shifted by one position.

I dug this up from IPython's codebase, in a utility module which allows pickling code objects: https://github.com/ipython/ipython/blob/master/IPython/utils/codeutil.py#L32

Need Your Help

Inside a batch file, how can I tell whether a process is running?

windows batch-file process

I'd like to write a batch file that checks to see if a process is running, and takes one action if it is, and another action if it isn't.

How to handle NHibernate sessions in an MVC4 project

nhibernate asp.net-mvc-4

I currently get my session from the globalasax as follows...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.