Skip to content

IPython broken on 3.8-dev, due to changes to ast.Module #11590

@njsmith

Description

@njsmith

In bpo-35766, Guido merged the "typed_ast" code that mypy used to maintain back into main CPython parser. This means that starting in 3.8, the regular ast module will contain information on type comments and type: ignore comments.

The type: ignore comments are stored in a list on the ast.Module object. This list is now mandatory. That means that this code is broken:

mod = ast.Module(nodelist)
async_wrapper_code = compiler(mod, 'cell_name', 'exec')

So is this:

mod = ast.Module([node])
code = compiler(mod, cell_name, "exec")

[BTW, why does one of those say 'cell_name' and the other says cell_name? Seems like one of those must be wrong... CC: @Carreau]

When you create a Module like this and try to compile it, then you get:

  TypeError: required field "type_ignores" missing from Module

On 3.8+, to create a Module object you have to instead write ast.Module(nodelist, []).

I filed a bug on python (bpo-35894), and Guido responded that the details of the AST like this aren't considered stable API, so he considers this a bug for IPython to fix, not a regression on CPython. So, now I'm filing a bug here instead :-).

The full changes are here, and AFAICT this line is the one that's breaking IPython.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions