{"id":13746619,"url":"https://github.com/serge-sans-paille/gast","last_synced_at":"2025-04-13T01:59:31.656Z","repository":{"id":9866667,"uuid":"63594069","full_name":"serge-sans-paille/gast","owner":"serge-sans-paille","description":"Python AST that abstracts the underlying Python version","archived":false,"fork":false,"pushed_at":"2025-02-16T20:15:18.000Z","size":134,"stargazers_count":144,"open_issues_count":0,"forks_count":37,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-13T01:59:25.042Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serge-sans-paille.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.rst","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-18T10:39:07.000Z","updated_at":"2025-02-16T20:15:22.000Z","dependencies_parsed_at":"2023-11-13T23:25:16.848Z","dependency_job_id":"eed0dc67-50da-4062-b0c2-2473d7cfe467","html_url":"https://github.com/serge-sans-paille/gast","commit_stats":{"total_commits":81,"total_committers":11,"mean_commits":7.363636363636363,"dds":"0.24691358024691357","last_synced_commit":"b4d2df626f69c9b6cdcbec5794708418a39c28a2"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serge-sans-paille%2Fgast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serge-sans-paille%2Fgast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serge-sans-paille%2Fgast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serge-sans-paille%2Fgast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serge-sans-paille","download_url":"https://codeload.github.com/serge-sans-paille/gast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654046,"owners_count":21140235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T06:00:57.104Z","updated_at":"2025-04-13T01:59:31.635Z","avatar_url":"https://github.com/serge-sans-paille.png","language":"Python","funding_links":[],"categories":["AST Tools"],"sub_categories":[],"readme":"GAST, daou naer!\n================\n\nA generic AST to represent Python2 and Python3's Abstract Syntax Tree(AST).\n\nGAST provides a compatibility layer between the AST of various Python versions,\nas produced by ``ast.parse`` from the standard ``ast`` module.\n\nBasic Usage\n-----------\n\n.. code:: python\n\n    \u003e\u003e\u003e import ast, gast\n    \u003e\u003e\u003e code = open('file.py').read()\n    \u003e\u003e\u003e tree = ast.parse(code)\n    \u003e\u003e\u003e gtree = gast.ast_to_gast(tree)\n    \u003e\u003e\u003e ... # process gtree\n    \u003e\u003e\u003e tree = gast.gast_to_ast(gtree)\n    \u003e\u003e\u003e ... # do stuff specific to tree\n\nAPI\n---\n\n``gast`` provides the same API as the ``ast`` module. All functions and classes\nfrom the ``ast`` module are also available in the ``gast`` module, and work\naccordingly on the ``gast`` tree.\n\nThree notable exceptions:\n\n1. ``gast.parse`` directly produces a GAST node. It's equivalent to running\n       ``gast.ast_to_gast`` on the output of ``ast.parse``.\n\n2. ``gast.dump`` dumps the ``gast`` common representation, not the original\n       one.\n\n3. ``gast.gast_to_ast`` and ``gast.ast_to_gast`` can be used to convert\n       from one ast to the other, back and forth.\n\nVersion Compatibility\n---------------------\n\nGAST is tested using ``tox`` and Travis on the following Python versions:\n\n- 2.7\n- 3.4\n- 3.5\n- 3.6\n- 3.7\n- 3.8\n- 3.9\n- 3.10\n- 3.11\n\n\nAST Changes\n-----------\n\n\nPython3\n*******\n\nThe AST used by GAST is the same as the one used in Python3.9, with the\nnotable exception of ``ast.arg`` being replaced by an ``ast.Name`` with an\n``ast.Param`` context.\n\nThe ``name`` field of ``ExceptHandler`` is represented as an ``ast.Name`` with\nan ``ast.Store`` context and not a ``str``.\n\nFor minor version before 3.9, please note that ``ExtSlice`` and ``Index`` are\nnot used.\n\nFor minor version before 3.8, please note that ``Ellipsis``, ``Num``, ``Str``,\n``Bytes`` and ``NamedConstant`` are represented as ``Constant``.\n\nPython2\n*******\n\nTo cope with Python3 features, several nodes from the Python2 AST are extended\nwith some new attributes/children, or represented by different nodes\n\n- ``ModuleDef`` nodes have a ``type_ignores`` attribute.\n\n- ``FunctionDef`` nodes have a ``returns`` attribute and a ``type_comment``\n  attribute.\n\n- ``ClassDef`` nodes have a ``keywords`` attribute.\n\n- ``With``'s ``context_expr`` and ``optional_vars`` fields are hold in a\n  ``withitem`` object.\n\n- ``For`` nodes have a ``type_comment`` attribute.\n\n- ``Raise``'s ``type``, ``inst`` and ``tback`` fields are hold in a single\n  ``exc`` field, using the transformation ``raise E, V, T =\u003e raise E(V).with_traceback(T)``.\n\n- ``TryExcept`` and ``TryFinally`` nodes are merged in the ``Try`` node.\n\n- ``arguments`` nodes have a ``kwonlyargs`` and ``kw_defaults`` attributes.\n\n- ``Call`` nodes loose their ``starargs`` attribute, replaced by an\n  argument wrapped in a ``Starred`` node. They also loose their ``kwargs``\n  attribute, wrapped in a ``keyword`` node with the identifier set to\n  ``None``, as done in Python3.\n\n- ``comprehension`` nodes have an ``async`` attribute (that is always set\n  to 0).\n\n- ``Ellipsis``, ``Num`` and ``Str`` nodes are represented as ``Constant``.\n\n- ``Subscript`` which don't have any ``Slice`` node as ``slice`` attribute (and\n  ``Ellipsis`` are not ``Slice`` nodes) no longer hold an ``ExtSlice`` but an\n  ``Index(Tuple(...))`` instead.\n\n\nPit Falls\n*********\n\n- In Python3, ``None``, ``True`` and ``False`` are parsed as ``Constant``\n  while they are parsed as regular ``Name`` in Python2.\n\nASDL\n****\n\nThis closely matches the one from https://docs.python.org/3/library/ast.html#abstract-grammar, with a few\ntrade-offs to cope with legacy ASTs.\n\n.. code::\n\n    -- ASDL's six builtin types are identifier, int, string, bytes, object, singleton\n\n    module Python\n    {\n        mod = Module(stmt* body, type_ignore *type_ignores)\n            | Interactive(stmt* body)\n            | Expression(expr body)\n            | FunctionType(expr* argtypes, expr returns)\n\n            -- not really an actual node but useful in Jython's typesystem.\n            | Suite(stmt* body)\n\n        stmt = FunctionDef(identifier name, arguments args,\n                           stmt* body, expr* decorator_list, expr? returns,\n                           string? type_comment, type_param* type_params)\n              | AsyncFunctionDef(identifier name, arguments args,\n                                 stmt* body, expr* decorator_list, expr? returns,\n                                 string? type_comment, type_param* type_params)\n\n              | ClassDef(identifier name,\n                 expr* bases,\n                 keyword* keywords,\n                 stmt* body,\n                 expr* decorator_list,\n                 type_param* type_params)\n              | Return(expr? value)\n\n              | Delete(expr* targets)\n              | Assign(expr* targets, expr value, string? type_comment)\n              | TypeAlias(expr name, type_param* type_params, expr value)\n              | AugAssign(expr target, operator op, expr value)\n              -- 'simple' indicates that we annotate simple name without parens\n              | AnnAssign(expr target, expr annotation, expr? value, int simple)\n\n              -- not sure if bool is allowed, can always use int\n              | Print(expr? dest, expr* values, bool nl)\n\n              -- use 'orelse' because else is a keyword in target languages\n              | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n              | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n              | While(expr test, stmt* body, stmt* orelse)\n              | If(expr test, stmt* body, stmt* orelse)\n              | With(withitem* items, stmt* body, string? type_comment)\n              | AsyncWith(withitem* items, stmt* body, string? type_comment)\n\n              | Match(expr subject, match_case* cases)\n\n              | Raise(expr? exc, expr? cause)\n              | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n              | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n              | Assert(expr test, expr? msg)\n\n              | Import(alias* names)\n              | ImportFrom(identifier? module, alias* names, int? level)\n\n              -- Doesn't capture requirement that locals must be\n              -- defined if globals is\n              -- still supports use as a function!\n              | Exec(expr body, expr? globals, expr? locals)\n\n              | Global(identifier* names)\n              | Nonlocal(identifier* names)\n              | Expr(expr value)\n              | Pass | Break | Continue\n\n              -- XXX Jython will be different\n              -- col_offset is the byte offset in the utf8 string the parser uses\n              attributes (int lineno, int col_offset)\n\n              -- BoolOp() can use left \u0026 right?\n        expr = BoolOp(boolop op, expr* values)\n             | NamedExpr(expr target, expr value)\n             | BinOp(expr left, operator op, expr right)\n             | UnaryOp(unaryop op, expr operand)\n             | Lambda(arguments args, expr body)\n             | IfExp(expr test, expr body, expr orelse)\n             | Dict(expr* keys, expr* values)\n             | Set(expr* elts)\n             | ListComp(expr elt, comprehension* generators)\n             | SetComp(expr elt, comprehension* generators)\n             | DictComp(expr key, expr value, comprehension* generators)\n             | GeneratorExp(expr elt, comprehension* generators)\n             -- the grammar constrains where yield expressions can occur\n             | Await(expr value)\n             | Yield(expr? value)\n             | YieldFrom(expr value)\n             -- need sequences for compare to distinguish between\n             -- x \u003c 4 \u003c 3 and (x \u003c 4) \u003c 3\n             | Compare(expr left, cmpop* ops, expr* comparators)\n             | Call(expr func, expr* args, keyword* keywords)\n             | Repr(expr value)\n             | FormattedValue(expr value, int? conversion, expr? format_spec)\n             | JoinedStr(expr* values)\n             | Constant(constant value, string? kind)\n\n             -- the following expression can appear in assignment context\n             | Attribute(expr value, identifier attr, expr_context ctx)\n             | Subscript(expr value, slice slice, expr_context ctx)\n             | Starred(expr value, expr_context ctx)\n             | Name(identifier id, expr_context ctx, expr? annotation,\n                    string? type_comment)\n             | List(expr* elts, expr_context ctx)\n             | Tuple(expr* elts, expr_context ctx)\n\n              -- col_offset is the byte offset in the utf8 string the parser uses\n              attributes (int lineno, int col_offset)\n\n        expr_context = Load | Store | Del | AugLoad | AugStore | Param\n\n        slice = Slice(expr? lower, expr? upper, expr? step)\n              | ExtSlice(slice* dims)\n              | Index(expr value)\n\n        boolop = And | Or\n\n        operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift\n                     | RShift | BitOr | BitXor | BitAnd | FloorDiv\n\n        unaryop = Invert | Not | UAdd | USub\n\n        cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn\n\n        comprehension = (expr target, expr iter, expr* ifs, int is_async)\n\n        excepthandler = ExceptHandler(expr? type, expr? name, stmt* body)\n                        attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)\n\n        arguments = (expr* args, expr* posonlyargs, expr? vararg, expr* kwonlyargs,\n                     expr* kw_defaults, expr? kwarg, expr* defaults)\n\n        -- keyword arguments supplied to call (NULL identifier for **kwargs)\n        keyword = (identifier? arg, expr value)\n\n        -- import name with optional 'as' alias.\n        alias = (identifier name, identifier? asname)\n                attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)\n\n        withitem = (expr context_expr, expr? optional_vars)\n\n        match_case = (pattern pattern, expr? guard, stmt* body)\n\n        pattern = MatchValue(expr value)\n                | MatchSingleton(constant value)\n                | MatchSequence(pattern* patterns)\n                | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n                | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n\n                | MatchStar(identifier? name)\n                -- The optional \"rest\" MatchMapping parameter handles capturing extra mapping keys\n\n                | MatchAs(pattern? pattern, identifier? name)\n                | MatchOr(pattern* patterns)\n\n                 attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)\n\n        type_ignore = TypeIgnore(int lineno, string tag)\n\n         type_param = TypeVar(identifier name, expr? bound)\n                    | ParamSpec(identifier name)\n                    | TypeVarTuple(identifier name)\n                    attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)\n    }\n\n\nReporting Bugs\n--------------\n\nBugs can be reported through `GitHub issues \u003chttps://github.com/serge-sans-paille/gast/issues\u003e`_.\n\nReporting Security Issues\n-------------------------\n\nIf for some reason, you think your bug is security-related and should be subject\nto responsible disclosure, don't hesitate to `contact the maintainer\n\u003cmailto:serge.guelton@telecom-bretagne.eu\u003e`_ directly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserge-sans-paille%2Fgast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserge-sans-paille%2Fgast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserge-sans-paille%2Fgast/lists"}