[Python] TypeError on CodeType creation in Python 3

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    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"""
    print(type(co_stacksize))
    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)


    Usage:

    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

    Continue reading...

Compartilhe esta Página