Giter Club home page Giter Club logo

gast's Introduction

GAST, daou naer!

A generic AST to represent Python2 and Python3's Abstract Syntax Tree(AST).

GAST provides a compatibility layer between the AST of various Python versions, as produced by ast.parse from the standard ast module.

Basic Usage

>>> import ast, gast
>>> code = open('file.py').read()
>>> tree = ast.parse(code)
>>> gtree = gast.ast_to_gast(tree)
>>> ... # process gtree
>>> tree = gast.gast_to_ast(gtree)
>>> ... # do stuff specific to tree

API

gast provides the same API as the ast module. All functions and classes from the ast module are also available in the gast module, and work accordingly on the gast tree.

Three notable exceptions:

  1. gast.parse directly produces a GAST node. It's equivalent to running
    gast.ast_to_gast on the output of ast.parse.
  2. gast.dump dumps the gast common representation, not the original
    one.
  3. gast.gast_to_ast and gast.ast_to_gast can be used to convert
    from one ast to the other, back and forth.

Version Compatibility

GAST is tested using tox and Travis on the following Python versions:

  • 2.7
  • 3.4
  • 3.5
  • 3.6
  • 3.7
  • 3.8
  • 3.9
  • 3.10
  • 3.11

AST Changes

Python3

The AST used by GAST is the same as the one used in Python3.9, with the notable exception of ast.arg being replaced by an ast.Name with an ast.Param context.

The name field of ExceptHandler is represented as an ast.Name with an ast.Store context and not a str.

For minor version before 3.9, please note that ExtSlice and Index are not used.

For minor version before 3.8, please note that Ellipsis, Num, Str, Bytes and NamedConstant are represented as Constant.

Python2

To cope with Python3 features, several nodes from the Python2 AST are extended with some new attributes/children, or represented by different nodes

  • ModuleDef nodes have a type_ignores attribute.
  • FunctionDef nodes have a returns attribute and a type_comment attribute.
  • ClassDef nodes have a keywords attribute.
  • With's context_expr and optional_vars fields are hold in a withitem object.
  • For nodes have a type_comment attribute.
  • Raise's type, inst and tback fields are hold in a single exc field, using the transformation raise E, V, T => raise E(V).with_traceback(T).
  • TryExcept and TryFinally nodes are merged in the Try node.
  • arguments nodes have a kwonlyargs and kw_defaults attributes.
  • Call nodes loose their starargs attribute, replaced by an argument wrapped in a Starred node. They also loose their kwargs attribute, wrapped in a keyword node with the identifier set to None, as done in Python3.
  • comprehension nodes have an async attribute (that is always set to 0).
  • Ellipsis, Num and Str nodes are represented as Constant.
  • Subscript which don't have any Slice node as slice attribute (and Ellipsis are not Slice nodes) no longer hold an ExtSlice but an Index(Tuple(...)) instead.

Pit Falls

  • In Python3, None, True and False are parsed as Constant while they are parsed as regular Name in Python2.

ASDL

This closely matches the one from https://docs.python.org/3/library/ast.html#abstract-grammar, with a few trade-offs to cope with legacy ASTs.

-- ASDL's six builtin types are identifier, int, string, bytes, object, singleton

module Python
{
    mod = Module(stmt* body, type_ignore *type_ignores)
        | Interactive(stmt* body)
        | Expression(expr body)
        | FunctionType(expr* argtypes, expr returns)

        -- not really an actual node but useful in Jython's typesystem.
        | Suite(stmt* body)

    stmt = FunctionDef(identifier name, arguments args,
                       stmt* body, expr* decorator_list, expr? returns,
                       string? type_comment, type_param* type_params)
          | AsyncFunctionDef(identifier name, arguments args,
                             stmt* body, expr* decorator_list, expr? returns,
                             string? type_comment, type_param* type_params)

          | ClassDef(identifier name,
             expr* bases,
             keyword* keywords,
             stmt* body,
             expr* decorator_list,
             type_param* type_params)
          | Return(expr? value)

          | Delete(expr* targets)
          | Assign(expr* targets, expr value, string? type_comment)
          | TypeAlias(expr name, type_param* type_params, expr value)
          | AugAssign(expr target, operator op, expr value)
          -- 'simple' indicates that we annotate simple name without parens
          | AnnAssign(expr target, expr annotation, expr? value, int simple)

          -- not sure if bool is allowed, can always use int
          | Print(expr? dest, expr* values, bool nl)

          -- use 'orelse' because else is a keyword in target languages
          | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
          | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
          | While(expr test, stmt* body, stmt* orelse)
          | If(expr test, stmt* body, stmt* orelse)
          | With(withitem* items, stmt* body, string? type_comment)
          | AsyncWith(withitem* items, stmt* body, string? type_comment)

          | Match(expr subject, match_case* cases)

          | Raise(expr? exc, expr? cause)
          | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
          | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
          | Assert(expr test, expr? msg)

          | Import(alias* names)
          | ImportFrom(identifier? module, alias* names, int? level)

          -- Doesn't capture requirement that locals must be
          -- defined if globals is
          -- still supports use as a function!
          | Exec(expr body, expr? globals, expr? locals)

          | Global(identifier* names)
          | Nonlocal(identifier* names)
          | Expr(expr value)
          | Pass | Break | Continue

          -- XXX Jython will be different
          -- col_offset is the byte offset in the utf8 string the parser uses
          attributes (int lineno, int col_offset)

          -- BoolOp() can use left & right?
    expr = BoolOp(boolop op, expr* values)
         | NamedExpr(expr target, expr value)
         | BinOp(expr left, operator op, expr right)
         | UnaryOp(unaryop op, expr operand)
         | Lambda(arguments args, expr body)
         | IfExp(expr test, expr body, expr orelse)
         | Dict(expr* keys, expr* values)
         | Set(expr* elts)
         | ListComp(expr elt, comprehension* generators)
         | SetComp(expr elt, comprehension* generators)
         | DictComp(expr key, expr value, comprehension* generators)
         | GeneratorExp(expr elt, comprehension* generators)
         -- the grammar constrains where yield expressions can occur
         | Await(expr value)
         | Yield(expr? value)
         | YieldFrom(expr value)
         -- need sequences for compare to distinguish between
         -- x < 4 < 3 and (x < 4) < 3
         | Compare(expr left, cmpop* ops, expr* comparators)
         | Call(expr func, expr* args, keyword* keywords)
         | Repr(expr value)
         | FormattedValue(expr value, int? conversion, expr? format_spec)
         | JoinedStr(expr* values)
         | Constant(constant value, string? kind)

         -- the following expression can appear in assignment context
         | Attribute(expr value, identifier attr, expr_context ctx)
         | Subscript(expr value, slice slice, expr_context ctx)
         | Starred(expr value, expr_context ctx)
         | Name(identifier id, expr_context ctx, expr? annotation,
                string? type_comment)
         | List(expr* elts, expr_context ctx)
         | Tuple(expr* elts, expr_context ctx)

          -- col_offset is the byte offset in the utf8 string the parser uses
          attributes (int lineno, int col_offset)

    expr_context = Load | Store | Del | AugLoad | AugStore | Param

    slice = Slice(expr? lower, expr? upper, expr? step)
          | ExtSlice(slice* dims)
          | Index(expr value)

    boolop = And | Or

    operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
                 | RShift | BitOr | BitXor | BitAnd | FloorDiv

    unaryop = Invert | Not | UAdd | USub

    cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn

    comprehension = (expr target, expr iter, expr* ifs, int is_async)

    excepthandler = ExceptHandler(expr? type, expr? name, stmt* body)
                    attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)

    arguments = (expr* args, expr* posonlyargs, expr? vararg, expr* kwonlyargs,
                 expr* kw_defaults, expr? kwarg, expr* defaults)

    -- keyword arguments supplied to call (NULL identifier for **kwargs)
    keyword = (identifier? arg, expr value)

    -- import name with optional 'as' alias.
    alias = (identifier name, identifier? asname)
            attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)

    withitem = (expr context_expr, expr? optional_vars)

    match_case = (pattern pattern, expr? guard, stmt* body)

    pattern = MatchValue(expr value)
            | MatchSingleton(constant value)
            | MatchSequence(pattern* patterns)
            | MatchMapping(expr* keys, pattern* patterns, identifier? rest)
            | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)

            | MatchStar(identifier? name)
            -- The optional "rest" MatchMapping parameter handles capturing extra mapping keys

            | MatchAs(pattern? pattern, identifier? name)
            | MatchOr(pattern* patterns)

             attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)

    type_ignore = TypeIgnore(int lineno, string tag)

     type_param = TypeVar(identifier name, expr? bound)
                | ParamSpec(identifier name)
                | TypeVarTuple(identifier name)
                attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
}

Reporting Bugs

Bugs can be reported through GitHub issues.

Reporting Security Issues

If for some reason, you think your bug is security-related and should be subject to responsible disclosure, don't hesitate to contact the maintainer directly.

gast's People

Contributors

curtlh avatar dbieber avatar ghisvail avatar hroncok avatar hugovk avatar jacklabarba avatar jendrikseipp avatar jfinkels avatar serge-sans-paille avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gast's Issues

Tag releases

Could you please tag releases to go with the pip releases?

Tuple instead of ExtSlice for gast 0.4.0

I get a bug which seems to be due to gast 0.4.0

A minimal example:

import gast as ast
import astunparse

code = "foo[:, b]"
tree = ast.parse(code)
code_back = astunparse.unparse(tree).strip()

node = tree.body[0]
subscript = node.value
print("astunparse.dump(subscript.slice):\n" + astunparse.dump(subscript.slice))

assert code == code_back, (code, code_back)

which gives:

$ pip install gast==0.3.3                                                                                  
Requirement already satisfied: gast==0.3.3 in /home/pierre/.pyenv/versions/3.8.2/lib/python3.8/site-packages (0.3.3)
$ python without_transonic.py                                                                              
astunparse.dump(subscript.slice):
ExtSlice(dims=[
  Slice(
    lower=None,
    upper=None,
    step=None),
  Index(value=Name(
    id='b',
    ctx=Load(),
    annotation=None,
    type_comment=None))])
$ pip install gast==0.4.0                                                                                  
Collecting gast==0.4.0
  Using cached gast-0.4.0-py3-none-any.whl (9.8 kB)
Installing collected packages: gast
  Attempting uninstall: gast
    Found existing installation: gast 0.3.3
    Uninstalling gast-0.3.3:
      Successfully uninstalled gast-0.3.3
Successfully installed gast-0.4.0
$ python without_transonic.py                                                                              
astunparse.dump(subscript.slice):
Tuple(
  elts=[
    Slice(
      lower=None,
      upper=None,
      step=None),
    Name(
      id='b',
      ctx=Load(),
      annotation=None,
      type_comment=None)],
  ctx=Load())
Traceback (most recent call last):
  File "without_transonic.py", line 12, in <module>
    assert code == code_back, (code, code_back)
AssertionError: ('foo[:, b]', 'foo[(:, b)]')

Incompatibility with astunparse

In astunparse/unparser.py, there is something like

    boolops = {ast.And: 'and', ast.Or: 'or'}
    boolops[op.__class__]

So we get something like:

boolops[gast.And]                                                  
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-5-1cb576efff8e> in <module>
----> 1 boolops[gast.And]

KeyError: <class 'gast.gast.And'>

Could it be solved from gast ?

It would be nice to be able to do (just for And and Or): {ast.And: "and"}[gast.And]

How can one unparse a tree produced with gast ?

Errors while Parsing Python2 code

Hi @serge-sans-paille ,

Need some clarifications regarding GAST parsing for Python2 source code.

  1. Getting error while parsing Python2 Print statement.
    print "Hello"

SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

  1. Showing error while having indentation issues in Python2 version code
class checkExistingUser(models.Model): #1
	privatekey = models.CharField(max_length=250, blank=True) #2
        emailid =  models.CharField(max_length=250,blank=True) #3

Got error in Line 3

TabError: inconsistent use of tabs and spaces in indentation

I need to know that whether the module can be able to parse Python2 version code.

Thanks in Advance.

Add some helpers for creating visitors

Hi, this really is a great library. Thanks for making it! May I suggest one improvement? It would be really useful if this library contained the basic boilerplate for creating visitors.

I was thinking of an expand function that yields the child nodes of the node that is given to it. Something like this:

def expand(node):
  if isinstance(node, Module):
    for stmt in node.body:
      yield stmt
     for type_ignore in node.type_ignores:
      yield type_ignore
  elif isinstance(node, Interactive):
   # and so on ...

I don't know if this is within the scope of this project, but it would be terribly useful to have. For example, I would be able define the following:

def preorder(root, expand):
    stack = [root]
    while len(stack) > 0:
        node = stack.pop()
        yield node
        for node in expand(top):
            stack.append(root)

And use it like so:

import gast

def has_return_stmt(node):
  for node in preorder(node, gast.expand):
    if isinstance(node, gast.Return):
      return True
  return False

I haven't looked at the code of this library yet, but if you want I can try to add this functionality.

Name constructor required 3 arguments prior to 0.3, and 4 arguments after

It looks like the new grammar added a 4th type_comment argument to Name nodes. Upgrading the code for this change would break existing users and force them to upgrade their gast installation. Is it possible to default this argument to None instead? Then the code would remain compatible across versions.

Making nodes actual subclasses of standard library nodes

Hi @serge-sans-paille,

I’m opening this issue to propose a change in the node generation process: that is to actually make gast nodes subclasses of standard library nodes, so that isinstance checks becomes compatible with standard library. This could ease adoption of gast since it would considerably reduce the amount of incompatibilities with the standard library.

Tell me what you think,

RFE: is it possible to start making github releases?🤔

Is it possible next time on release new version make the github release to have entry on https://github.com/serge-sans-paille/gast/releases? 🤔

I'm asking because only on make gh release is spread notification about new release to those who have set watch->releases.
My automation process those notification trying make preliminary automated upgrade of building packages which allow save some time on maintaining packaging procedures.

More about gh releases is possible to find on
https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
https://github.com/marketplace/actions/github-release
https://pgjones.dev/blog/trusted-plublishing-2023/

Version conflict with Jupyter-LSP?

When trying to interact with jupyter-lsp, I get the following on my devtools:

lsp-ws-connection initialization failure Error: pkg_resources.ContextualVersionConflict: (gast 0.4.0 (/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages), Requirement.parse('gast~=0.3.3'), {'beniget'})
    o index.js:10
    M index.js:10
    M index.js:10
    M index.js:10
    u setImmediate.js:16
    d setImmediate.js:31
    n setImmediate.js:87
index.js:10:526255

Or in my jupyter terminal:

2020-09-10 15:46:22,274 UTC - ERROR - pyls_jsonrpc.endpoint - Failed to handle request 0
Traceback (most recent call last):
  File "/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages/pyls_jsonrpc/endpoint.py", line 113, in consume
    self._handle_request(message['id'], message['method'], message.get('params'))
  File "/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages/pyls_jsonrpc/endpoint.py", line 182, in _handle_request
    handler_result = handler(params)
  File "/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages/pyls_jsonrpc/dispatchers.py", line 23, in handler
    return method(**(params or {}))
  File "/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages/pyls/python_ls.py", line 208, in m_initialize
    self.config = config.Config(rootUri, initializationOptions or {},
  File "/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages/pyls/config/config.py", line 53, in __init__
    entry_point.load()
  File "/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2471, in load
    self.require(*args, **kwargs)
  File "/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2494, in require
    items = working_set.resolve(reqs, env, installer, extras=self.extras)
  File "/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages/pkg_resources/__init__.py", line 790, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (gast 0.4.0 (/home/mariana/miniconda3/envs/pyls-memestra/lib/python3.8/site-packages), Requirement.parse('gast~=0.3.3'), {'beniget'})

If you're interested in reproducing the steps are:

  1. Create an environment that contains:
    conda install -c conda-forge memestra jupyter-lsp 'jupyterlab>=2,<2.1.0a0' 'nodejs>=13' python-language-server pyls-memestra
  2. jupyter labextension install @krassowski/jupyterlab-lsp
  3. Clone pyls-memestra repo: [email protected]:QuantStack/pyls-memestra.git
  4. Open jupyter lab and run the example

If you do the same thing but with gast=0.3.3, everything works perfectly.

Please let me know if I can be of any other assistance to you!

I thought it might be something with my python version?
Here is a cc of my conda list. Thanks!

Test failures with Python 3.13.0b1

I tried if gast-0.5.4 works with recently released Python 3.13.0b1 and lots of tests fail. This is the output:

python3.13 -m unittest discover -v
test_NodeConstructor (tests.test_api.APITestCase.test_NodeConstructor) ... ok
test_NodeTransformer (tests.test_api.APITestCase.test_NodeTransformer) ... ok
test_NodeVisitor (tests.test_api.APITestCase.test_NodeVisitor) ... ok
test_copy_location (tests.test_api.APITestCase.test_copy_location) ... ok
test_dump (tests.test_api.APITestCase.test_dump) ... FAIL
test_fix_missing_locations (tests.test_api.APITestCase.test_fix_missing_locations) ... ok
test_get_docstring (tests.test_api.APITestCase.test_get_docstring) ... ok
test_increment_lineno (tests.test_api.APITestCase.test_increment_lineno) ... ok
test_iter_child_nodes (tests.test_api.APITestCase.test_iter_child_nodes) ... ok
test_iter_fields (tests.test_api.APITestCase.test_iter_fields) ... ok
test_literal_eval_code (tests.test_api.APITestCase.test_literal_eval_code) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Expression.__init__ missing 1 required positional argument: 'body'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: List.__init__ missing 1 required positional argument: 'ctx'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Constant.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
ok
test_literal_eval_string (tests.test_api.APITestCase.test_literal_eval_string) ... ok
test_parse (tests.test_api.APITestCase.test_parse) ... ok
test_unparse (tests.test_api.APITestCase.test_unparse) ... ok
test_walk (tests.test_api.APITestCase.test_walk) ... FAIL
test_ArgAnnotation (tests.test_compat.CompatTestCase.test_ArgAnnotation) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: FunctionDef.__init__ missing 1 required positional argument: 'name'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: FunctionDef.__init__ missing 1 required positional argument: 'args'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_Call (tests.test_compat.CompatTestCase.test_Call) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Expr.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Call.__init__ missing 1 required positional argument: 'func'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Starred.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Starred.__init__ missing 1 required positional argument: 'ctx'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: keyword.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_Ellipsis (tests.test_compat.CompatTestCase.test_Ellipsis) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Subscript.__init__ missing 1 required positional argument: 'slice'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Subscript.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Subscript.__init__ missing 1 required positional argument: 'ctx'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_ExtSlice (tests.test_compat.CompatTestCase.test_ExtSlice) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Tuple.__init__ missing 1 required positional argument: 'ctx'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_ExtSliceEllipsis (tests.test_compat.CompatTestCase.test_ExtSliceEllipsis) ... FAIL
test_ExtSlices (tests.test_compat.CompatTestCase.test_ExtSlices) ... FAIL
test_FormattedValue (tests.test_compat.CompatTestCase.test_FormattedValue) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: FormattedValue.__init__ missing 1 required positional argument: 'conversion'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: FormattedValue.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_Index (tests.test_compat.CompatTestCase.test_Index) ... FAIL
test_JoinedStr (tests.test_compat.CompatTestCase.test_JoinedStr) ... FAIL
test_KeywordOnlyArgument (tests.test_compat.CompatTestCase.test_KeywordOnlyArgument) ... FAIL
test_MatchAs (tests.test_compat.CompatTestCase.test_MatchAs) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Match.__init__ missing 1 required positional argument: 'subject'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: match_case.__init__ missing 1 required positional argument: 'pattern'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: MatchValue.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_MatchClass (tests.test_compat.CompatTestCase.test_MatchClass) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: MatchClass.__init__ missing 1 required positional argument: 'cls'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_MatchMapping (tests.test_compat.CompatTestCase.test_MatchMapping) ... FAIL
test_MatchOr (tests.test_compat.CompatTestCase.test_MatchOr) ... FAIL
test_MatchSequence (tests.test_compat.CompatTestCase.test_MatchSequence) ... FAIL
test_MatchSingleton (tests.test_compat.CompatTestCase.test_MatchSingleton) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: MatchSingleton.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_MatchStar (tests.test_compat.CompatTestCase.test_MatchStar) ... FAIL
test_MatchValue (tests.test_compat.CompatTestCase.test_MatchValue) ... FAIL
test_NamedExpr (tests.test_compat.CompatTestCase.test_NamedExpr) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: NamedExpr.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: NamedExpr.__init__ missing 1 required positional argument: 'target'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_PosonlyArgs (tests.test_compat.CompatTestCase.test_PosonlyArgs) ... FAIL
test_Raise (tests.test_compat.CompatTestCase.test_Raise) ... FAIL
test_TryExcept (tests.test_compat.CompatTestCase.test_TryExcept) ... FAIL
test_TryExceptNamed (tests.test_compat.CompatTestCase.test_TryExceptNamed) ... FAIL
test_TryFinally (tests.test_compat.CompatTestCase.test_TryFinally) ... FAIL
test_TryStar (tests.test_compat.CompatTestCase.test_TryStar) ... ok
test_TypeIgnore (tests.test_compat.CompatTestCase.test_TypeIgnore) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: TypeIgnore.__init__ missing 1 required positional argument: 'tag'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: TypeIgnore.__init__ missing 1 required positional argument: 'lineno'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_With (tests.test_compat.CompatTestCase.test_With) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: withitem.__init__ missing 1 required positional argument: 'context_expr'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
FAIL
test_keyword_argument (tests.test_compat.CompatTestCase.test_keyword_argument) ... FAIL
test_star_argument (tests.test_compat.CompatTestCase.test_star_argument) ... FAIL
testCompile (tests.test_self.SelfTestCase.testCompile) ... /var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: alias.__init__ missing 1 required positional argument: 'name'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: ClassDef.__init__ missing 1 required positional argument: 'name'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Attribute.__init__ missing 1 required positional argument: 'attr'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Attribute.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Attribute.__init__ missing 1 required positional argument: 'ctx'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: If.__init__ missing 1 required positional argument: 'test'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Compare.__init__ missing 1 required positional argument: 'left'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: BinOp.__init__ missing 1 required positional argument: 'op'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: BinOp.__init__ missing 1 required positional argument: 'left'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: BinOp.__init__ missing 1 required positional argument: 'right'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: BoolOp.__init__ missing 1 required positional argument: 'op'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: ListComp.__init__ missing 1 required positional argument: 'elt'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: comprehension.__init__ missing 1 required positional argument: 'iter'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: comprehension.__init__ missing 1 required positional argument: 'is_async'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: comprehension.__init__ missing 1 required positional argument: 'target'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: UnaryOp.__init__ missing 1 required positional argument: 'op'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: UnaryOp.__init__ missing 1 required positional argument: 'operand'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: GeneratorExp.__init__ missing 1 required positional argument: 'elt'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: For.__init__ missing 1 required positional argument: 'target'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: For.__init__ missing 1 required positional argument: 'iter'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Lambda.__init__ missing 1 required positional argument: 'body'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Lambda.__init__ missing 1 required positional argument: 'args'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: AugAssign.__init__ missing 1 required positional argument: 'op'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: AugAssign.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: AugAssign.__init__ missing 1 required positional argument: 'target'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: DictComp.__init__ missing 1 required positional argument: 'key'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: DictComp.__init__ missing 1 required positional argument: 'value'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: While.__init__ missing 1 required positional argument: 'test'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/gast/astn.py:20: DeprecationWarning: Assert.__init__ missing 1 required positional argument: 'test'. This will become an error in Python 3.15.
  new_node = getattr(to, cls)()
ok
testParse (tests.test_self.SelfTestCase.testParse) ... ok
test_unparse (tests.test_self.SelfTestCase.test_unparse) ... ok

======================================================================
FAIL: test_dump (tests.test_api.APITestCase.test_dump)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_api.py", line 44, in test_dump
    self.assertEqual(dump, norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: "Expr[59 chars]ram())]), body=Name(id='x', ctx=Load())))" != "Expr[59 chars]ram(), annotation=None, type_comment=None)], p[148 chars]e)))"
- Expression(body=Lambda(args=arguments(args=[Name(id='x', ctx=Param())]), body=Name(id='x', ctx=Load())))
+ Expression(body=Lambda(args=arguments(args=[Name(id='x', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=Name(id='x', ctx=Load(), annotation=None, type_comment=None)))


======================================================================
FAIL: test_walk (tests.test_api.APITestCase.test_walk)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_api.py", line 53, in test_walk
    self.assertEqual(dump, norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: "Expr[41 chars]oad()), op=Add(), right=Constant(value=1)))" != "Expr[41 chars]oad(), annotation=None, type_comment=None), op[40 chars]e)))"
- Expression(body=BinOp(left=Name(id='x', ctx=Load()), op=Add(), right=Constant(value=1)))
+ Expression(body=BinOp(left=Name(id='x', ctx=Load(), annotation=None, type_comment=None), op=Add(), right=Constant(value=1, kind=None)))
?                                                   ++++++++++++++++++++++++++++++++++++                                   +++++++++++


======================================================================
FAIL: test_ArgAnnotation (tests.test_compat.CompatTestCase.test_ArgAnnotation)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 42, in test_ArgAnnotation
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[111 chars]oad()))]), body=[Pass()])])" != "Modu[111 chars]oad(), annotation=None, type_comment=None), ty[186 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='x', ctx=Param(), annotation=Name(id='int', ctx=Load()))]), body=[Pass()])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='x', ctx=Param(), annotation=Name(id='int', ctx=Load(), annotation=None, type_comment=None), type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Pass()], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_Call (tests.test_compat.CompatTestCase.test_Call)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 334, in test_Call
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[50 chars]oad()), args=[Name(id='x', ctx=Load()), Starre[149 chars]))])" != "Modu[50 chars]oad(), annotation=None, type_comment=None), ar[331 chars]=[])"
- Module(body=[Expr(value=Call(func=Name(id='foo', ctx=Load()), args=[Name(id='x', ctx=Load()), Starred(value=Name(id='args', ctx=Load()), ctx=Load())], keywords=[keyword(arg='y', value=Constant(value=1)), keyword(value=Name(id='kwargs', ctx=Load()))]))])
+ Module(body=[Expr(value=Call(func=Name(id='foo', ctx=Load(), annotation=None, type_comment=None), args=[Name(id='x', ctx=Load(), annotation=None, type_comment=None), Starred(value=Name(id='args', ctx=Load(), annotation=None, type_comment=None), ctx=Load())], keywords=[keyword(arg='y', value=Constant(value=1, kind=None)), keyword(arg=None, value=Name(id='kwargs', ctx=Load(), annotation=None, type_comment=None))]))], type_ignores=[])


======================================================================
FAIL: test_Ellipsis (tests.test_compat.CompatTestCase.test_Ellipsis)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 438, in test_Ellipsis
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[73 chars]ram())]), body=[Expr(value=Subscript(value=Nam[67 chars]])])" != "Modu[73 chars]ram(), annotation=None, type_comment=None)], p[304 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param())]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load()), slice=Constant(value=Ellipsis), ctx=Load()))])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Constant(value=Ellipsis, kind=None), ctx=Load()))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_ExtSlice (tests.test_compat.CompatTestCase.test_ExtSlice)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 407, in test_ExtSlice
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[73 chars]ram())]), body=[Expr(value=Subscript(value=Nam[85 chars]])])" != "Modu[73 chars]ram(), annotation=None, type_comment=None)], p[377 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param())]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load()), slice=Tuple(elts=[Slice(), Slice()], ctx=Load()), ctx=Load()))])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Tuple(elts=[Slice(lower=None, upper=None, step=None), Slice(lower=None, upper=None, step=None)], ctx=Load()), ctx=Load()))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_ExtSliceEllipsis (tests.test_compat.CompatTestCase.test_ExtSliceEllipsis)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 454, in test_ExtSliceEllipsis
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[73 chars]ram())]), body=[Expr(value=Subscript(value=Nam[112 chars]])])" != "Modu[73 chars]ram(), annotation=None, type_comment=None)], p[360 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param())]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load()), slice=Tuple(elts=[Constant(value=1), Constant(value=Ellipsis)], ctx=Load()), ctx=Load()))])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Tuple(elts=[Constant(value=1, kind=None), Constant(value=Ellipsis, kind=None)], ctx=Load()), ctx=Load()))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_ExtSlices (tests.test_compat.CompatTestCase.test_ExtSlices)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 423, in test_ExtSlices
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[73 chars]ram())]), body=[Expr(value=Subscript(value=Nam[95 chars]])])" != "Modu[73 chars]ram(), annotation=None, type_comment=None)], p[365 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param())]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load()), slice=Tuple(elts=[Constant(value=1), Slice()], ctx=Load()), ctx=Load()))])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Tuple(elts=[Constant(value=1, kind=None), Slice(lower=None, upper=None, step=None)], ctx=Load()), ctx=Load()))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_FormattedValue (tests.test_compat.CompatTestCase.test_FormattedValue)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 70, in test_FormattedValue
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[44 chars]ore())], value=Constant(value=1)), Expr(value=[80 chars]))])" != "Modu[44 chars]ore(), annotation=None, type_comment=None)], v[217 chars]=[])"
- Module(body=[Assign(targets=[Name(id='e', ctx=Store())], value=Constant(value=1)), Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='e', ctx=Load()), conversion=-1)]))])
+ Module(body=[Assign(targets=[Name(id='e', ctx=Store(), annotation=None, type_comment=None)], value=Constant(value=1, kind=None), type_comment=None), Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='e', ctx=Load(), annotation=None, type_comment=None), conversion=-1, format_spec=None)]))], type_ignores=[])


======================================================================
FAIL: test_Index (tests.test_compat.CompatTestCase.test_Index)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 391, in test_Index
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[73 chars]ram())]), body=[Expr(value=Subscript(value=Nam[60 chars]])])" != "Modu[73 chars]ram(), annotation=None, type_comment=None)], p[297 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param())]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load()), slice=Constant(value=1), ctx=Load()))])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Constant(value=1, kind=None), ctx=Load()))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_JoinedStr (tests.test_compat.CompatTestCase.test_JoinedStr)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 85, in test_JoinedStr
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[44 chars]ore())], value=Constant(value=1)), Expr(value=[104 chars]))])" != "Modu[44 chars]ore(), annotation=None, type_comment=None)], v[252 chars]=[])"
- Module(body=[Assign(targets=[Name(id='e', ctx=Store())], value=Constant(value=1)), Expr(value=JoinedStr(values=[Constant(value='e = '), FormattedValue(value=Name(id='e', ctx=Load()), conversion=-1)]))])
+ Module(body=[Assign(targets=[Name(id='e', ctx=Store(), annotation=None, type_comment=None)], value=Constant(value=1, kind=None), type_comment=None), Expr(value=JoinedStr(values=[Constant(value='e = ', kind=None), FormattedValue(value=Name(id='e', ctx=Load(), annotation=None, type_comment=None), conversion=-1, format_spec=None)]))], type_ignores=[])


======================================================================
FAIL: test_KeywordOnlyArgument (tests.test_compat.CompatTestCase.test_KeywordOnlyArgument)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 54, in test_KeywordOnlyArgument
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[43 chars]ents(kwonlyargs=[Name(id='x', ctx=Param())], k[45 chars]])])" != "Modu[43 chars]ents(args=[], posonlyargs=[], vararg=None, kwo[224 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(kwonlyargs=[Name(id='x', ctx=Param())], kw_defaults=[Constant(value=1)]), body=[Pass()])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[], posonlyargs=[], vararg=None, kwonlyargs=[Name(id='x', ctx=Param(), annotation=None, type_comment=None)], kw_defaults=[Constant(value=1, kind=None)], kwarg=None, defaults=[]), body=[Pass()], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_MatchAs (tests.test_compat.CompatTestCase.test_MatchAs)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 216, in test_MatchAs
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[41 chars]oad()), cases=[match_case(pattern=MatchSequenc[118 chars]])])" != "Modu[41 chars]oad(), annotation=None, type_comment=None), ca[219 chars]=[])"
- Module(body=[Match(subject=Name(id='v', ctx=Load()), cases=[match_case(pattern=MatchSequence(patterns=[MatchValue(value=Constant(value=1)), MatchAs(name='other')]), body=[Expr(value=Constant(value=Ellipsis))])])])
+ Module(body=[Match(subject=Name(id='v', ctx=Load(), annotation=None, type_comment=None), cases=[match_case(pattern=MatchSequence(patterns=[MatchValue(value=Constant(value=1, kind=None)), MatchAs(pattern=None, name='other')]), guard=None, body=[Expr(value=Constant(value=Ellipsis, kind=None))])])], type_ignores=[])


======================================================================
FAIL: test_MatchClass (tests.test_compat.CompatTestCase.test_MatchClass)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 190, in test_MatchClass
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[41 chars]oad()), cases=[match_case(pattern=MatchClass(c[148 chars]])])" != "Modu[41 chars]oad(), annotation=None, type_comment=None), ca[284 chars]=[])"
- Module(body=[Match(subject=Name(id='v', ctx=Load()), cases=[match_case(pattern=MatchClass(cls=Name(id='Cls', ctx=Load()), kwd_attrs=['attr'], kwd_patterns=[MatchValue(value=Constant(value=1))]), body=[Expr(value=Constant(value=Ellipsis))])])])
+ Module(body=[Match(subject=Name(id='v', ctx=Load(), annotation=None, type_comment=None), cases=[match_case(pattern=MatchClass(cls=Name(id='Cls', ctx=Load(), annotation=None, type_comment=None), patterns=[], kwd_attrs=['attr'], kwd_patterns=[MatchValue(value=Constant(value=1, kind=None))]), guard=None, body=[Expr(value=Constant(value=Ellipsis, kind=None))])])], type_ignores=[])


======================================================================
FAIL: test_MatchMapping (tests.test_compat.CompatTestCase.test_MatchMapping)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 176, in test_MatchMapping
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[41 chars]oad()), cases=[match_case(pattern=MatchMapping[102 chars]])])" != "Modu[41 chars]oad(), annotation=None, type_comment=None), ca[214 chars]=[])"
- Module(body=[Match(subject=Name(id='v', ctx=Load()), cases=[match_case(pattern=MatchMapping(keys=[Constant(value=1)], patterns=[MatchAs(name='a')]), body=[Expr(value=Constant(value=Ellipsis))])])])
+ Module(body=[Match(subject=Name(id='v', ctx=Load(), annotation=None, type_comment=None), cases=[match_case(pattern=MatchMapping(keys=[Constant(value=1, kind=None)], patterns=[MatchAs(pattern=None, name='a')], rest=None), guard=None, body=[Expr(value=Constant(value=Ellipsis, kind=None))])])], type_ignores=[])


======================================================================
FAIL: test_MatchOr (tests.test_compat.CompatTestCase.test_MatchOr)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 229, in test_MatchOr
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[41 chars]oad()), cases=[match_case(pattern=MatchOr(patt[126 chars]])])" != "Modu[41 chars]oad(), annotation=None, type_comment=None), ca[224 chars]=[])"
- Module(body=[Match(subject=Name(id='v', ctx=Load()), cases=[match_case(pattern=MatchOr(patterns=[MatchValue(value=Constant(value=1)), MatchValue(value=Constant(value=2))]), body=[Expr(value=Constant(value=Ellipsis))])])])
+ Module(body=[Match(subject=Name(id='v', ctx=Load(), annotation=None, type_comment=None), cases=[match_case(pattern=MatchOr(patterns=[MatchValue(value=Constant(value=1, kind=None)), MatchValue(value=Constant(value=2, kind=None))]), guard=None, body=[Expr(value=Constant(value=Ellipsis, kind=None))])])], type_ignores=[])


======================================================================
FAIL: test_MatchSequence (tests.test_compat.CompatTestCase.test_MatchSequence)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 163, in test_MatchSequence
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[41 chars]oad()), cases=[match_case(pattern=MatchSequenc[96 chars]])])" != "Modu[41 chars]oad(), annotation=None, type_comment=None), ca[200 chars]=[])"
- Module(body=[Match(subject=Name(id='v', ctx=Load()), cases=[match_case(pattern=MatchSequence(patterns=[MatchAs(name='a'), MatchAs(name='b')]), body=[Expr(value=Constant(value=Ellipsis))])])])
+ Module(body=[Match(subject=Name(id='v', ctx=Load(), annotation=None, type_comment=None), cases=[match_case(pattern=MatchSequence(patterns=[MatchAs(pattern=None, name='a'), MatchAs(pattern=None, name='b')]), guard=None, body=[Expr(value=Constant(value=Ellipsis, kind=None))])])], type_ignores=[])


======================================================================
FAIL: test_MatchSingleton (tests.test_compat.CompatTestCase.test_MatchSingleton)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 150, in test_MatchSingleton
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[41 chars]oad()), cases=[match_case(pattern=MatchSinglet[50 chars]])])" != "Modu[41 chars]oad(), annotation=None, type_comment=None), ca[136 chars]=[])"
- Module(body=[Match(subject=Name(id='v', ctx=Load()), cases=[match_case(pattern=MatchSingleton(), body=[Expr(value=Constant(value=Ellipsis))])])])
+ Module(body=[Match(subject=Name(id='v', ctx=Load(), annotation=None, type_comment=None), cases=[match_case(pattern=MatchSingleton(value=None), guard=None, body=[Expr(value=Constant(value=Ellipsis, kind=None))])])], type_ignores=[])


======================================================================
FAIL: test_MatchStar (tests.test_compat.CompatTestCase.test_MatchStar)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 203, in test_MatchStar
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[41 chars]oad()), cases=[match_case(pattern=MatchSequenc[120 chars]])])" != "Modu[41 chars]oad(), annotation=None, type_comment=None), ca[207 chars]=[])"
- Module(body=[Match(subject=Name(id='v', ctx=Load()), cases=[match_case(pattern=MatchSequence(patterns=[MatchValue(value=Constant(value=1)), MatchStar(name='other')]), body=[Expr(value=Constant(value=Ellipsis))])])])
+ Module(body=[Match(subject=Name(id='v', ctx=Load(), annotation=None, type_comment=None), cases=[match_case(pattern=MatchSequence(patterns=[MatchValue(value=Constant(value=1, kind=None)), MatchStar(name='other')]), guard=None, body=[Expr(value=Constant(value=Ellipsis, kind=None))])])], type_ignores=[])


======================================================================
FAIL: test_MatchValue (tests.test_compat.CompatTestCase.test_MatchValue)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 138, in test_MatchValue
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[41 chars]oad()), cases=[match_case(pattern=MatchValue(v[75 chars]])])" != "Modu[41 chars]oad(), annotation=None, type_comment=None), ca[162 chars]=[])"
- Module(body=[Match(subject=Name(id='v', ctx=Load()), cases=[match_case(pattern=MatchValue(value=Constant(value='hello')), body=[Expr(value=Constant(value=Ellipsis))])])])
+ Module(body=[Match(subject=Name(id='v', ctx=Load(), annotation=None, type_comment=None), cases=[match_case(pattern=MatchValue(value=Constant(value='hello', kind=None)), guard=None, body=[Expr(value=Constant(value=Ellipsis, kind=None))])])], type_ignores=[])


======================================================================
FAIL: test_NamedExpr (tests.test_compat.CompatTestCase.test_NamedExpr)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 123, in test_NamedExpr
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[56 chars]ore()), value=Constant(value=1)))])" != "Modu[56 chars]ore(), annotation=None, type_comment=None), va[49 chars]=[])"
- Module(body=[Expr(value=NamedExpr(target=Name(id='x', ctx=Store()), value=Constant(value=1)))])
+ Module(body=[Expr(value=NamedExpr(target=Name(id='x', ctx=Store(), annotation=None, type_comment=None), value=Constant(value=1, kind=None)))], type_ignores=[])
?                                                                  ++++++++++++++++++++++++++++++++++++                         +++++++++++    +++++++++++++++++


======================================================================
FAIL: test_PosonlyArgs (tests.test_compat.CompatTestCase.test_PosonlyArgs)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 113, in test_PosonlyArgs
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[73 chars]ram())], posonlyargs=[Name(id='a', ctx=Param()[17 chars]])])" != "Modu[73 chars]ram(), annotation=None, type_comment=None)], p[227 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='b', ctx=Param())], posonlyargs=[Name(id='a', ctx=Param())]), body=[Pass()])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='b', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Pass()], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_Raise (tests.test_compat.CompatTestCase.test_Raise)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 318, in test_Raise
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[45 chars]oad()))])" != "Modu[45 chars]oad(), annotation=None, type_comment=None), ca[24 chars]=[])"
- Module(body=[Raise(exc=Name(id='Exception', ctx=Load()))])
+ Module(body=[Raise(exc=Name(id='Exception', ctx=Load(), annotation=None, type_comment=None), cause=None)], type_ignores=[])


======================================================================
FAIL: test_TryExcept (tests.test_compat.CompatTestCase.test_TryExcept)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 266, in test_TryExcept
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[75 chars]oad()), body=[Pass()])], orelse=[Pass()])])" != "Modu[75 chars]oad(), annotation=None, type_comment=None), na[71 chars]=[])"
- Module(body=[Try(body=[Pass()], handlers=[ExceptHandler(type=Name(id='e', ctx=Load()), body=[Pass()])], orelse=[Pass()])])
+ Module(body=[Try(body=[Pass()], handlers=[ExceptHandler(type=Name(id='e', ctx=Load(), annotation=None, type_comment=None), name=None, body=[Pass()])], orelse=[Pass()], finalbody=[])], type_ignores=[])


======================================================================
FAIL: test_TryExceptNamed (tests.test_compat.CompatTestCase.test_TryExceptNamed)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 277, in test_TryExceptNamed
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[75 chars]oad()), name=Name(id='f', ctx=Store()), body=[[25 chars]])])" != "Modu[75 chars]oad(), annotation=None, type_comment=None), na[128 chars]=[])"
- Module(body=[Try(body=[Pass()], handlers=[ExceptHandler(type=Name(id='e', ctx=Load()), name=Name(id='f', ctx=Store()), body=[Pass()])], orelse=[Pass()])])
+ Module(body=[Try(body=[Pass()], handlers=[ExceptHandler(type=Name(id='e', ctx=Load(), annotation=None, type_comment=None), name=Name(id='f', ctx=Store(), annotation=None, type_comment=None), body=[Pass()])], orelse=[Pass()], finalbody=[])], type_ignores=[])


======================================================================
FAIL: test_TryFinally (tests.test_compat.CompatTestCase.test_TryFinally)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 353, in test_TryFinally
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'Modu[23 chars]()], finalbody=[Pass()])])' != 'Modu[23 chars]()], handlers=[], orelse=[], finalbody=[Pass()[17 chars]=[])'
- Module(body=[Try(body=[Pass()], finalbody=[Pass()])])
+ Module(body=[Try(body=[Pass()], handlers=[], orelse=[], finalbody=[Pass()])], type_ignores=[])


======================================================================
FAIL: test_TypeIgnore (tests.test_compat.CompatTestCase.test_TypeIgnore)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 99, in test_TypeIgnore
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[43 chars]ents(), body=[Pass()])], type_ignores=[TypeIgn[27 chars]')])" != "Modu[43 chars]ents(args=[], posonlyargs=[], vararg=None, kwo[171 chars]')])"
- Module(body=[FunctionDef(name='foo', args=arguments(), body=[Pass()])], type_ignores=[TypeIgnore(lineno=1, tag='[excuse]')])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Pass()], decorator_list=[], returns=None, type_comment=None)], type_ignores=[TypeIgnore(lineno=1, tag='[excuse]')])


======================================================================
FAIL: test_With (tests.test_compat.CompatTestCase.test_With)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 345, in test_With
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[74 chars]oad()), args=[Constant(value='any')]))], body=[Pass()])])" != "Modu[74 chars]oad(), annotation=None, type_comment=None), ar[123 chars]=[])"
- Module(body=[With(items=[withitem(context_expr=Call(func=Name(id='open', ctx=Load()), args=[Constant(value='any')]))], body=[Pass()])])
+ Module(body=[With(items=[withitem(context_expr=Call(func=Name(id='open', ctx=Load(), annotation=None, type_comment=None), args=[Constant(value='any', kind=None)], keywords=[]), optional_vars=None)], body=[Pass()], type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_keyword_argument (tests.test_compat.CompatTestCase.test_keyword_argument)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 377, in test_keyword_argument
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[43 chars]ents(kwarg=Name(id='a', ctx=Param())), body=[Pass()])])" != "Modu[43 chars]ents(args=[], posonlyargs=[], vararg=None, kwo[192 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(kwarg=Name(id='a', ctx=Param())), body=[Pass()])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=Name(id='a', ctx=Param(), annotation=None, type_comment=None), defaults=[]), body=[Pass()], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


======================================================================
FAIL: test_star_argument (tests.test_compat.CompatTestCase.test_star_argument)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/gast-0.5.4/work/gast-0.5.4/tests/test_compat.py", line 365, in test_star_argument
    self.assertEqual(gast.dump(tree), norm)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: "Modu[43 chars]ents(vararg=Name(id='a', ctx=Param())), body=[Pass()])])" != "Modu[43 chars]ents(args=[], posonlyargs=[], vararg=Name(id='[192 chars]=[])"
- Module(body=[FunctionDef(name='foo', args=arguments(vararg=Name(id='a', ctx=Param())), body=[Pass()])])
+ Module(body=[FunctionDef(name='foo', args=arguments(args=[], posonlyargs=[], vararg=Name(id='a', ctx=Param(), annotation=None, type_comment=None), kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Pass()], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])


----------------------------------------------------------------------
Ran 47 tests in 0.545s

FAILED (failures=30)

Starargs and varargs nodes do not have attributes set

On Python 2.7

In [1]: import gast

In [2]: src = """
...: def f(x, y, *a):
...: return x * y
...: """

In [3]: gast.dump(gast.parse(src), include_attributes=True)
AttributeError: 'Name' object has no attribute 'lineno'

This does not occur under Python 3.5.

What seems to be happening AFAICT is that the arguments nodes do not have lineno and col_offset attributes, so the ast.copy_location calls in ast2.py on lines 135 and 141 do nothing.

I am not sure what the best way to fix this would be: the parent of the arguments node (if any) would have the correct location information, or it would be possible to call fix_missing_locations on the parent at the end, but both are a little bit messy to put into the visitor.

Full stack trace:


AttributeError Traceback (most recent call last)
in ()
----> 1 gast.dump(gast.parse(src), include_attributes=True)

/usr/lib/python2.7/ast.pyc in dump(node, annotate_fields, include_attributes)
108 if not isinstance(node, AST):
109 raise TypeError('expected AST, got %r' % node.class.name)
--> 110 return _format(node)
111
112

/usr/lib/python2.7/ast.pyc in _format(node)
92 def _format(node):
93 if isinstance(node, AST):
---> 94 fields = [(a, _format(b)) for a, b in iter_fields(node)]
95 rv = '%s(%s' % (node.class.name, ', '.join(
96 ('%s=%s' % field for field in fields)

/usr/lib/python2.7/ast.pyc in _format(node)
104 return rv + ')'
105 elif isinstance(node, list):
--> 106 return '[%s]' % ', '.join(_format(x) for x in node)
107 return repr(node)
108 if not isinstance(node, AST):

/usr/lib/python2.7/ast.pyc in ((x,))
104 return rv + ')'
105 elif isinstance(node, list):
--> 106 return '[%s]' % ', '.join(_format(x) for x in node)
107 return repr(node)
108 if not isinstance(node, AST):

/usr/lib/python2.7/ast.pyc in _format(node)
92 def _format(node):
93 if isinstance(node, AST):
---> 94 fields = [(a, _format(b)) for a, b in iter_fields(node)]
95 rv = '%s(%s' % (node.class.name, ', '.join(
96 ('%s=%s' % field for field in fields)

/usr/lib/python2.7/ast.pyc in _format(node)
92 def _format(node):
93 if isinstance(node, AST):
---> 94 fields = [(a, _format(b)) for a, b in iter_fields(node)]
95 rv = '%s(%s' % (node.class.name, ', '.join(
96 ('%s=%s' % field for field in fields)

/usr/lib/python2.7/ast.pyc in _format(node)
101 rv += fields and ', ' or ' '
102 rv += ', '.join('%s=%s' % (a, _format(getattr(node, a)))
--> 103 for a in node._attributes)
104 return rv + ')'
105 elif isinstance(node, list):

/usr/lib/python2.7/ast.pyc in ((a,))
101 rv += fields and ', ' or ' '
102 rv += ', '.join('%s=%s' % (a, _format(getattr(node, a)))
--> 103 for a in node._attributes)
104 return rv + ')'
105 elif isinstance(node, list):

AttributeError: 'Name' object has no attribute 'lineno'

User should be able to use same boolean literal AST nodes on Python 2 and Python 3

Currently, in gast 0.1.4, Python 2 has Name(id='True') but Python 3 has NameConstant(value=True).

$ python2 -c "import gast; print(gast.dump(gast.parse('True')))"
Module(body=[Expr(value=Name(id='True', ctx=Load(), annotation=None))])
$ python3 -c "import gast; print(gast.dump(gast.parse('True')))"
Module(body=[Expr(value=NameConstant(value=True))])

I expected NameConstant(value=True) in both situations.

Publish sdist and bdist wheel

The benefits of wheels are well documented. See: https://pythonwheels.com/
This package is pure Python and publishing it as both source and as a wheel is simple

Would you accept a PR that adds a simple Makefile or documentation that describes how to release this package as both a sdist and bdist_wheel?

Python 3.6 f-strings are not supported by gast

What happens with gast:

$ python3.6 -c "import gast; print(gast.dump(gast.parse('f\'{x}\'')))"
Module(body=[Expr(value=None)])

What happens with standard ast:

$ python3.6 -c "import ast; print(ast.dump(ast.parse('f\'{x}\'')))"
Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1, format_spec=None)]))])

Add support for Python 3.6

Currently, the test suite fails for Python 3.6:

$ python3.6 -m unittest tests.test_self.SelfTestCase.testCompile
[...]/gast/tests/test_self.py:20: ResourceWarning: unclosed file <_io.TextIOWrapper name='[...]/gast/gast/ast3.py' mode='r' encoding='UTF-8'>
  content = open(src_py).read()
E
======================================================================
ERROR: testCompile (tests.test_self.SelfTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "[...]/gast/tests/test_self.py", line 22, in testCompile
    compile(gast.gast_to_ast(gnode), src_py, 'exec')
TypeError: required field "is_async" missing from comprehension

----------------------------------------------------------------------
Ran 1 test in 0.057s

FAILED (errors=1)

(Travis can build with Python 3.6 and 3.7-dev).

Test failures with Python 3.9

With Python 3.9.0b4, I get:

$ tox -e py39
GLOB sdist-make: .../gast/setup.py
py39 inst-nodeps: .../gast/.tox/.tmp/package/1/gast-0.3.3.zip
py39 installed: apipkg==1.5,astunparse==1.6.3,attrs==19.3.0,execnet==1.7.1,gast==0.3.3,more-itertools==8.4.0,packaging==20.4,pep8==1.7.1,pluggy==0.13.1,py==1.9.0,pyparsing==2.4.7,pytest==5.4.3,pytest-cache==1.0,pytest-pep8==1.0.6,six==1.15.0,wcwidth==0.2.5
py39 run-test-pre: PYTHONHASHSEED='155329557'
py39 run-test: commands[0] | py.test --pep8
.../gast/.tox/py39/lib/python3.9/site-packages/pep8.py:110: FutureWarning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
============================= test session starts ==============================
platform linux -- Python 3.9.0b4, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
cachedir: .tox/py39/.pytest_cache
rootdir: .../gast
plugins: pep8-1.0.6
collected 45 items

setup.py .                                                               [  2%]
gast/__init__.py .                                                       [  4%]
gast/ast2.py .                                                           [  6%]
gast/ast3.py .                                                           [  8%]
gast/astn.py .                                                           [ 11%]
gast/gast.py .                                                           [ 13%]
tests/__init__.py .                                                      [ 15%]
tests/test_api.py .......F......                                         [ 46%]
tests/test_compat.py ..FFFFF.F...........                                [ 91%]
tests/test_self.py .F..                                                  [100%]

=================================== FAILURES ===================================
______________________ APITestCase.test_increment_lineno _______________________

self = <tests.test_api.APITestCase testMethod=test_increment_lineno>

    def test_increment_lineno(self):
        tree = gast.Constant(value=1, kind=None)
        tree.lineno = 1
>       gast.increment_lineno(tree)

tests/test_api.py:64: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

node = <gast.gast.Constant object at 0x7fec385de850>, n = 1

    def increment_lineno(node, n=1):
        """
        Increment the line number and end line number of each node in the tree
        starting at *node* by *n*. This is useful to "move code" to a different
        location in a file.
        """
        for child in walk(node):
            if 'lineno' in child._attributes:
                child.lineno = getattr(child, 'lineno', 0) + n
            if 'end_lineno' in child._attributes:
>               child.end_lineno = getattr(child, 'end_lineno', 0) + n
E               TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

gast/gast.py:379: TypeError
___________________________ CompatTestCase.test_Call ___________________________

self = <tests.test_compat.CompatTestCase testMethod=test_Call>

    def test_Call(self):
        self.maxDiff = None
        code = 'foo(x, y=1, *args, **kwargs)'
        tree = gast.parse(code)
>       compile(gast.gast_to_ast(tree), '<test>', 'exec')
E       TypeError: required field "lineno" missing from keyword

tests/test_compat.py:191: TypeError
_________________________ CompatTestCase.test_Ellipsis _________________________

self = <tests.test_compat.CompatTestCase testMethod=test_Ellipsis>

    def test_Ellipsis(self):
        self.maxDiff = None
        code = 'def foo(a): a[...]'
        tree = gast.parse(code)
        compile(gast.gast_to_ast(tree), '<test>', 'exec')
        norm = ("Module(body=[FunctionDef(name='foo', args=arguments(args=["
                "Name(id='a', ctx=Param(), annotation=None, type_comment=None)"
                "], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[]"
                ", kwarg=None, defaults=[]), body=[Expr(value=Subscript(value="
                "Name(id='a', ctx=Load(), annotation=None, type_comment=None)"
                ", slice=Index(value=Constant(value=Ellipsis, kind=None)), ctx"
                "=Load()))], decorator_list=[], returns=None, type_comment="
                "None)], type_ignores=[])")
>       self.assertEqual(gast.dump(tree), norm)
E       AssertionError: "Modu[300 chars]lice=Constant(value=Ellipsis, kind=None), ctx=[77 chars]=[])" != "Modu[300 chars]lice=Index(value=Constant(value=Ellipsis, kind[90 chars]=[])"
E       - Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Constant(value=Ellipsis, kind=None), ctx=Load()))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])
E       ?                                                                                                                                                                                                                                                                                                                                                         ^
E       + Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Index(value=Constant(value=Ellipsis, kind=None)), ctx=Load()))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])
E       ?                                                                                                                                                                                                                                                                                                                    ++++++++++++                                     ^^

tests/test_compat.py:303: AssertionError
_________________________ CompatTestCase.test_ExtSlice _________________________

self = <tests.test_compat.CompatTestCase testMethod=test_ExtSlice>

    def test_ExtSlice(self):
        code = 'def foo(a): a[:,:]'
        tree = gast.parse(code)
>       compile(gast.gast_to_ast(tree), '<test>', 'exec')
E       TypeError: required field "lineno" missing from expr

tests/test_compat.py:263: TypeError
_____________________ CompatTestCase.test_ExtSliceEllipsis _____________________

self = <tests.test_compat.CompatTestCase testMethod=test_ExtSliceEllipsis>

    def test_ExtSliceEllipsis(self):
        self.maxDiff = None
        code = 'def foo(a): a[1, ...]'
        tree = gast.parse(code)
        compile(gast.gast_to_ast(tree), '<test>', 'exec')
        norm = ("Module(body=[FunctionDef(name='foo', args=arguments(args=["
                "Name(id='a', ctx=Param(), annotation=None, type_comment=None)"
                "], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[]"
                ", kwarg=None, defaults=[]), body=[Expr(value=Subscript(value="
                "Name(id='a', ctx=Load(), annotation=None, type_comment=None)"
                ", slice=Index(value=Tuple(elts=[Constant(value=1, kind=None)"
                ", Constant(value=Ellipsis, kind=None)], ctx=Load())), ctx="
                "Load()))], decorator_list=[], returns=None, type_comment="
                "None)], type_ignores=[])")
>       self.assertEqual(gast.dump(tree), norm)
E       AssertionError: "Modu[300 chars]lice=Tuple(elts=[Constant(value=1, kind=None),[133 chars]=[])" != "Modu[300 chars]lice=Index(value=Tuple(elts=[Constant(value=1,[146 chars]=[])"
E       - Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Tuple(elts=[Constant(value=1, kind=None), Constant(value=Ellipsis, kind=None)], ctx=Load()), ctx=Load()))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])
E       ?                                                                                                                                                                                                                                                                                                                                                                                                                 ^
E       + Module(body=[FunctionDef(name='foo', args=arguments(args=[Name(id='a', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Index(value=Tuple(elts=[Constant(value=1, kind=None), Constant(value=Ellipsis, kind=None)], ctx=Load())), ctx=Load()))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])
E       ?                                                                                                                                                                                                                                                                                                                    ++++++++++++                                                                                             ^^

tests/test_compat.py:319: AssertionError
________________________ CompatTestCase.test_ExtSlices _________________________

self = <tests.test_compat.CompatTestCase testMethod=test_ExtSlices>

    def test_ExtSlices(self):
        code = 'def foo(a): a[1,:]'
        tree = gast.parse(code)
>       compile(gast.gast_to_ast(tree), '<test>', 'exec')
E       TypeError: required field "lineno" missing from expr

tests/test_compat.py:278: TypeError
__________________________ CompatTestCase.test_Index ___________________________

self = <tests.test_compat.CompatTestCase testMethod=test_Index>

    def test_Index(self):
        code = 'def foo(a): a[1]'
        tree = gast.parse(code)
        compile(gast.gast_to_ast(tree), '<test>', 'exec')
        norm = ("Module(body=[FunctionDef(name='foo', args=arguments(args=["
                "Name(id='a', ctx=Param(), annotation=None, type_comment=None)"
                "], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[]"
                ", kwarg=None, defaults=[]), body=[Expr(value=Subscript(value="
                "Name(id='a', ctx=Load(), annotation=None, type_comment=None)"
                ", slice=Index(value=Constant(value=1, kind=None)), ctx=Load()"
                "))], decorator_list=[], returns=None, type_comment=None)]"
                ", type_ignores=[])")
>       self.assertEqual(gast.dump(tree), norm)
E       AssertionError: "Modu[300 chars]lice=Constant(value=1, kind=None), ctx=Load())[70 chars]=[])" != "Modu[300 chars]lice=Index(value=Constant(value=1, kind=None))[83 chars]=[])"
E       Diff is 1563 characters long. Set self.maxDiff to None to see it.

tests/test_compat.py:258: AssertionError
___________________________ SelfTestCase.testCompile ___________________________

self = <tests.test_self.SelfTestCase testMethod=testCompile>

    def testCompile(self):
        for src_py in self.srcs:
            with open(src_py) as f:
                content = f.read()
            gnode = gast.parse(content)
>           compile(gast.gast_to_ast(gnode), src_py, 'exec')
E           TypeError: required field "lineno" missing from keyword

tests/test_self.py:26: TypeError
=============================== warnings summary ===============================
.tox/py39/lib/python3.9/site-packages/pytest_pep8.py:38: 10 tests with warnings
  .../gast/.tox/py39/lib/python3.9/site-packages/pytest_pep8.py:38: PytestDeprecationWarning: direct construction of Pep8Item has been deprecated, please use Pep8Item.from_parent
    return Pep8Item(path, parent, pep8ignore, config._max_line_length)

.tox/py39/lib/python3.9/site-packages/_pytest/nodes.py:254
  .../gast/.tox/py39/lib/python3.9/site-packages/_pytest/nodes.py:254: PytestUnknownMarkWarning: Unknown pytest.mark.pep8 - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
    marker_ = getattr(MARK_GEN, marker)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=========================== short test summary info ============================
FAILED tests/test_api.py::APITestCase::test_increment_lineno - TypeError: uns...
FAILED tests/test_compat.py::CompatTestCase::test_Call - TypeError: required ...
FAILED tests/test_compat.py::CompatTestCase::test_Ellipsis - AssertionError: ...
FAILED tests/test_compat.py::CompatTestCase::test_ExtSlice - TypeError: requi...
FAILED tests/test_compat.py::CompatTestCase::test_ExtSliceEllipsis - Assertio...
FAILED tests/test_compat.py::CompatTestCase::test_ExtSlices - TypeError: requ...
FAILED tests/test_compat.py::CompatTestCase::test_Index - AssertionError: "Mo...
FAILED tests/test_self.py::SelfTestCase::testCompile - TypeError: required fi...
================== 8 failed, 37 passed, 11 warnings in 0.36s ===================
ERROR: InvocationError for command .../gast/.tox/py39/bin/py.test --pep8 (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   py39: commands failed

Provide gast.unparse?

ast.unparse is available since Python 3.9, are there any plan to have an equivalent gast.unparse?

why ast not support [] () to use in express

i have a code to be parsed like this
self.atom(_func=self.vm_list[0].try_execute, _args='pkill iperf3')
but i can't find list's index info in ast_obj,how can i deal with this express?

gast doesn't seem to parse assignment expressions correctly

It looks like gast doesn't correctly parse assignment expressions (the := operator):

ast:

In [1]: import ast

In [2]: expr = "(x := 1)"

In [3]: ast.dump(ast.parse(expr))
Out[3]: "Module(body=[Expr(value=NamedExpr(target=Name(id='x', ctx=Store()), value=Constant(value=1, kind=None)))], type_ignores=[])"

gast:

In [4]: import gast

In [5]: expr = "(x := 1)"

In [6]: gast.dump(gast.parse(expr))
Out[6]: 'Module(body=[Expr(value=None)], type_ignores=[])'

module 'gast' has no attribute 'Index'

System information

Describe the current behavior

WARNING:tensorflow:AutoGraph could not transform 
<function train_step at 0x7f15c0790ee0> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, 
set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: module 'gast' has no attribute 'Index'

Describe the expected behavior

Standalone code to reproduce the issue
python transformer.py

Other info / logs Include any logs or source code that would be helpful to
transformer.zip

GitHub CI doesn't test Python 2

setup.py and tox.ini both claim to support Python 2.7, but the GitHub CI only runs the tests on Python 3 at the moment - so I'm not sure if the intention is still to support Python 2 or not.

(There are some Python 3-isms in gast/unparse.py that cause test failures with gast 0.5.3 on Python 2: at least the definition of _ALL_QUOTES, * arguments, and various f"" strings...)

[incompatible] Why ExtSlice and Index are not used after gast 3.9 ?

"For minor version before 3.9, please note that ExtSlice and Index are not used."

My project used gast 0.3.3, which has gast.Index and my project rely on the analysis of gast.Index. Now it's upgraded to version 0.4.0, gast.Index is removed, which cause incompatibility.

For example:

source = "a[i]"

gast_node = gast.parse(source)
print(gast.dump(ast_node))

Before 3.9

Module(body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Index(value=Name(id='i', ctx=Load(), annotation=None, type_comment=None)), ctx=Load()))], type_ignores=[])

NOTE: slice=Index(value=Name(...))

After 3.9

Module(body=[Expr(value=Subscript(value=Name(id='a', ctx=Load(), annotation=None, type_comment=None), slice=Name(id='i', ctx=Load(), annotation=None, type_comment=None), ctx=Load()))], type_ignores=[])

NOTE: slice=Name(...), Index is removed.

Python 3.8 failures

In Fedora, we try to rebuild packages with Python 3.8.0b1. This is gast 0.2.2:

/usr/bin/python3 setup.py test
testCompile (tests.test_self.SelfTestCase) ... ERROR
testParse (tests.test_self.SelfTestCase) ... ok
test_unparse (tests.test_self.SelfTestCase) ... ERROR
test_NodeTransformer (tests.test_api.APITestCase) ... ok
test_NodeVisitor (tests.test_api.APITestCase) ... ok
test_copy_location (tests.test_api.APITestCase) ... ok
test_dump (tests.test_api.APITestCase) ... ok
test_fix_missing_locations (tests.test_api.APITestCase) ... ok
test_get_docstring (tests.test_api.APITestCase) ... FAIL
test_increment_lineno (tests.test_api.APITestCase) ... ok
test_iter_child_nodes (tests.test_api.APITestCase) ... ok
test_iter_fields (tests.test_api.APITestCase) ... ok
test_literal_eval_code (tests.test_api.APITestCase) ... ok
test_literal_eval_string (tests.test_api.APITestCase) ... ok
test_parse (tests.test_api.APITestCase) ... ok
test_walk (tests.test_api.APITestCase) ... FAIL
test_ArgAnnotation (tests.test_compat.CompatTestCase) ... ERROR
test_Call (tests.test_compat.CompatTestCase) ... ERROR
test_FormattedValue (tests.test_compat.CompatTestCase) ... ERROR
test_JoinedStr (tests.test_compat.CompatTestCase) ... ERROR
test_KeywordOnlyArgument (tests.test_compat.CompatTestCase) ... ERROR
test_TryExceptNamed (tests.test_compat.CompatTestCase) ... ERROR

======================================================================
ERROR: testCompile (tests.test_self.SelfTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_self.py", line 27, in testCompile
    compile(gast.gast_to_ast(gnode), src_py, 'exec')
TypeError: arguments field "posonlyargs" must be a list, not a NoneType

======================================================================
ERROR: test_unparse (tests.test_self.SelfTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_self.py", line 34, in test_unparse
    astunparse.unparse(gast.gast_to_ast(gnode))
  File "/usr/lib/python3.8/site-packages/astunparse/__init__.py", line 13, in unparse
    Unparser(tree, file=v)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 38, in __init__
    self.dispatch(tree)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 66, in dispatch
    meth(tree)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 78, in _Module
    self.dispatch(stmt)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 66, in dispatch
    meth(tree)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 328, in _ClassDef
    self.dispatch(t.body)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 63, in dispatch
    self.dispatch(t)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 66, in dispatch
    meth(tree)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 347, in _FunctionDef
    self._generic_FunctionDef(t)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 337, in _generic_FunctionDef
    self.dispatch(t.args)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 66, in dispatch
    meth(tree)
  File "/usr/lib/python3.8/site-packages/astunparse/unparser.py", line 763, in _arguments
    defaults = [None] * (len(t.args) - len(t.defaults)) + t.defaults
AttributeError: 'arguments' object has no attribute 'defaults'

======================================================================
ERROR: test_ArgAnnotation (tests.test_compat.CompatTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_compat.py", line 48, in test_ArgAnnotation
    compile(gast.gast_to_ast(tree), '<test>', 'exec')
TypeError: arguments field "posonlyargs" must be a list, not a NoneType

======================================================================
ERROR: test_Call (tests.test_compat.CompatTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_compat.py", line 63, in test_Call
    compile(gast.gast_to_ast(tree), '<test>', 'exec')
ValueError: field value is required for keyword

======================================================================
ERROR: test_FormattedValue (tests.test_compat.CompatTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_compat.py", line 70, in test_FormattedValue
    compile(gast.gast_to_ast(tree), '<test>', 'exec')
ValueError: field value is required for Assign

======================================================================
ERROR: test_JoinedStr (tests.test_compat.CompatTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_compat.py", line 75, in test_JoinedStr
    compile(gast.gast_to_ast(tree), '<test>', 'exec')
ValueError: field value is required for Assign

======================================================================
ERROR: test_KeywordOnlyArgument (tests.test_compat.CompatTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_compat.py", line 53, in test_KeywordOnlyArgument
    compile(gast.gast_to_ast(tree), '<test>', 'exec')
TypeError: arguments field "posonlyargs" must be a list, not a NoneType

======================================================================
ERROR: test_TryExceptNamed (tests.test_compat.CompatTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_compat.py", line 58, in test_TryExceptNamed
    compile(gast.gast_to_ast(tree), '<test>', 'exec')
TypeError: required field "type_ignores" missing from Module

======================================================================
FAIL: test_get_docstring (tests.test_api.APITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_api.py", line 69, in test_get_docstring
    self.assertEqual(docs, "foo")
AssertionError: None != 'foo'

======================================================================
FAIL: test_walk (tests.test_api.APITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/gast-0.2.2/tests/test_api.py", line 45, in test_walk
    self.assertEqual(dump, norm)
AssertionError: "Expr[30 chars]='x', ctx=Load(), annotation=None), op=Add(), right=None))" != "Expr[30 chars]='x', ctx=Load(), annotation=None), op=Add(), right=Num(n=1)))"
- Expression(body=BinOp(left=Name(id='x', ctx=Load(), annotation=None), op=Add(), right=None))
?                                                                                        ^ ^
+ Expression(body=BinOp(left=Name(id='x', ctx=Load(), annotation=None), op=Add(), right=Num(n=1)))
?                                                                                        ^^^ ^^^


----------------------------------------------------------------------
Ran 22 tests in 0.069s

FAILED (failures=2, errors=8)

User should be able to use gast.parse with astunparse.unparse on Python 3.3, 3.4

Currently, in gast 0.1.4, Python 3 versions less than 3.5 (for example, 3.3 and 3.4) don't play nicely with the AST unparsing library astunparse. The particular issue is in unparsing a function call produced by gast_to_ast():

$ python3.4 -c "from gast import gast_to_ast, parse; from astunparse import unparse; unparse(gast_to_ast(parse('foo()')))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/jeffrey/src/gast/.env34/lib/python3.4/site-packages/astunparse/__init__.py", line 13, in unparse
    Unparser(tree, file=v)
  File "/home/jeffrey/src/gast/.env34/lib/python3.4/site-packages/astunparse/unparser.py", line 38, in __init__
    self.dispatch(tree)
  File "/home/jeffrey/src/gast/.env34/lib/python3.4/site-packages/astunparse/unparser.py", line 66, in dispatch
    meth(tree)
  File "/home/jeffrey/src/gast/.env34/lib/python3.4/site-packages/astunparse/unparser.py", line 78, in _Module
    self.dispatch(stmt)
  File "/home/jeffrey/src/gast/.env34/lib/python3.4/site-packages/astunparse/unparser.py", line 66, in dispatch
    meth(tree)
  File "/home/jeffrey/src/gast/.env34/lib/python3.4/site-packages/astunparse/unparser.py", line 90, in _Expr
    self.dispatch(tree.value)
  File "/home/jeffrey/src/gast/.env34/lib/python3.4/site-packages/astunparse/unparser.py", line 66, in dispatch
    meth(tree)
  File "/home/jeffrey/src/gast/.env34/lib/python3.4/site-packages/astunparse/unparser.py", line 649, in _Call
    if t.starargs:
AttributeError: 'Call' object has no attribute 'starargs'

My guess is that gast_to_ast outputs code that is Python 3.5 compatible, but not Python 3.4 compatible:

$ python3.4 -c "import ast; print(ast.dump(ast.parse('foo()')))"
Module(body=[Expr(value=Call(func=Name(id='foo', ctx=Load()), args=[], keywords=[], starargs=None, kwargs=None))])
$ python3.4 -c "import ast, gast; print(ast.dump(gast.gast_to_ast(gast.ast_to_gast(ast.parse('foo()')))))"
Module(body=[Expr(value=Call(func=Name(id='foo', ctx=Load()), args=[], keywords=[]))])

Support match statement

Gast does not currently support match statement. Would be important to have support for all python syntax.

>>> code = '''
... match command.split():
...     case ["drop", *objects]:
...         for obj in objects:
...             character.drop(obj, current_room)
...     # The rest of your commands go here
... '''
>>> repr(gast.parse(code).body[0])
'None'
>>> repr(ast.parse(code).body[0])
'<ast.Match object at 0x10a5e7ac0>'

Same goes for the try-star satement

there maybe something wrong with unparse

i want to change the dangerous express to the safe one, so i use ast to parse the code want to get the info from the line.
from
self.atom(_func=self.vm_list[0].try_execute, _args='pkill iperf3')
change to
self.vm_list[0].try_execute('pkill iperf3')
so i need to get value behind _func values "self.vm_list[0].try_execute" and value behind _args values "'pkill iperf3'"
i wonder if there is a better way to deal this prob

ast.Assign need type_comment in Python3.8

In python3.8.5,I use gast to modify ast_node then convert back into ast bygast_to_ast. But the result is different with original ast.

It works in Python3.5 and Python2.7

The example code:

import ast
import gast
import textwrap
import unittest

def code_gast_ast(source):
    """
    Transform source_code into gast.Node and modify it,
    then back to ast.Node.
    """
    source = textwrap.dedent(source)
    root = gast.parse(source)
    new_root = GastNodeTransformer(root).apply()
    ast_root = gast.gast_to_ast(new_root)
    return ast.dump(ast_root)


def code_ast(source):
    """
    Transform source_code into ast.Node, then dump it.
    """
    source = textwrap.dedent(source)
    root = ast.parse(source)
    return ast.dump(root)


class GastNodeTransformer(gast.NodeTransformer):
    def __init__(self, root):
        self.root = root

    def apply(self):
        return self.generic_visit(self.root)

    def visit_Name(self, node):
        """
        Param in func is ast.Name in PY2, but ast.arg in PY3.
        It will be generally represented by gast.Name in gast.
        """
        if isinstance(node.ctx, gast.Param) and node.id != "self":
            node.id += '_new'

        return node

class TestPythonCompatibility(unittest.TestCase):
    def _check_compatibility(self, source, target):
        source_dump = code_gast_ast(source)
        target_dump = code_ast(target)
        self.assertEqual(source_dump, target_dump)

    def test_call(self):
        source = """
            y = foo(*arg)
        """
        target = """
            y = foo(*arg_new)
        """
        self._check_compatibility(source, target)

# source_dump  gast-> ast
# Module(body=[Assign(targets=[Name(id='y', ctx=Store())], value=Call(func=Name(id='foo', ctx=Load()), args=[Starred(value=Name(id='arg_new', ctx=Load()), ctx=Load())], keywords=[]))], type_ignores=[])

# target_dump ast
# Module(body=[Assign(targets=[Name(id='y', ctx=Store())], value=Call(func=Name(id='foo', ctx=Load()), args=[Starred(value=Name(id='arg_new', ctx=Load()), ctx=Load())], keywords=[]), type_comment=None)], type_ignores=[])

After I modified the defination in gast.py, it works in python3.8

from

('Assign', (('targets', 'value',),
                ('lineno', 'col_offset', 'end_lineno', 'end_col_offset',),
                (stmt,))),

into

('Assign', (('targets', 'value','type_comment'),
                ('lineno', 'col_offset', 'end_lineno', 'end_col_offset',),
                (stmt,))),

Starred arguments are not correctly found on Python version < 3.5

On Python 3.5

$ python3.5 -c "import gast; print(gast.dump(gast.parse('f(*a)')))"
Module(body=[Expr(value=Call(func=Name(id='f', ctx=Load(), annotation=None), args=[Starred(value=Name(id='a', ctx=Load(), annotation=None), ctx=Load())], keywords=[]))])

On Python 3.4

$ python3.4 -c "import gast; print(gast.dump(gast.parse('f(*a)')))"
Module(body=[Expr(value=Call(func=Name(id='f', ctx=Load(), annotation=None), args=[], keywords=[]))])

There is a similar issue for kwargs.

Ellipsis symbol missing

Hi, it seems that the 0.3 release is missing some symbols like Ellipsis. Is this intentional?

Python 3.10: TypeError: required field "lineno" missing from alias

Hello. We get a test failure in Fedora when we build gast with Python 3.10 betas:

$  tox -e py310
GLOB sdist-make: .../gast/setup.py
py310 inst-nodeps: .../gast/.tox/.tmp/package/1/gast-0.4.0.zip
py310 installed: astunparse==1.6.3,attrs==21.2.0,gast @ file://.../gast/.tox/.tmp/package/1/gast-0.4.0.zip,iniconfig==1.1.1,packaging==20.9,pluggy==0.13.1,py==1.10.0,pyparsing==2.4.7,pytest==6.2.4,six==1.16.0,toml==0.10.2
py310 run-test-pre: PYTHONHASHSEED='3466862442'
py310 run-test: commands[0] | pytest
============================= test session starts ==============================
platform linux -- Python 3.10.0b3, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
cachedir: .tox/py310/.pytest_cache
rootdir: .../gast
collected 35 items

tests/test_api.py .............                                          [ 37%]
tests/test_compat.py ...................                                 [ 91%]
tests/test_self.py F..                                                   [100%]

=================================== FAILURES ===================================
___________________________ SelfTestCase.testCompile ___________________________

self = <tests.test_self.SelfTestCase testMethod=testCompile>

    def testCompile(self):
        for src_py in self.srcs:
            with open(src_py) as f:
                content = f.read()
            gnode = gast.parse(content)
>           compile(gast.gast_to_ast(gnode), src_py, 'exec')
E           TypeError: required field "lineno" missing from alias

tests/test_self.py:26: TypeError
=========================== short test summary info ============================
FAILED tests/test_self.py::SelfTestCase::testCompile - TypeError: required fi...
========================= 1 failed, 34 passed in 0.24s =========================
ERROR: InvocationError for command .../gast/.tox/py310/bin/pytest (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   py310: commands failed

This might be related to PEP 626.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.