{"id":16247791,"url":"https://github.com/mbdevpl/typed-astunparse","last_synced_at":"2025-08-21T06:32:13.812Z","repository":{"id":57477206,"uuid":"61291340","full_name":"mbdevpl/typed-astunparse","owner":"mbdevpl","description":"Python 3 AST unparser with type comments support.","archived":false,"fork":false,"pushed_at":"2019-10-24T14:31:40.000Z","size":157,"stargazers_count":30,"open_issues_count":2,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-15T23:31:27.685Z","etag":null,"topics":["abstact-syntax-tree","code-generation","code-generator","type-annotations"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbdevpl.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":null,"support":null}},"created_at":"2016-06-16T12:35:19.000Z","updated_at":"2024-12-02T01:00:51.000Z","dependencies_parsed_at":"2022-09-14T17:11:19.348Z","dependency_job_id":null,"html_url":"https://github.com/mbdevpl/typed-astunparse","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbdevpl%2Ftyped-astunparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbdevpl%2Ftyped-astunparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbdevpl%2Ftyped-astunparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbdevpl%2Ftyped-astunparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbdevpl","download_url":"https://codeload.github.com/mbdevpl/typed-astunparse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230494900,"owners_count":18235047,"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":["abstact-syntax-tree","code-generation","code-generator","type-annotations"],"created_at":"2024-10-10T14:38:39.860Z","updated_at":"2024-12-19T20:14:19.185Z","avatar_url":"https://github.com/mbdevpl.png","language":"Python","readme":".. role:: bash(code)\n    :language: bash\n\n.. role:: python(code)\n    :language: python\n\n\n================\ntyped-astunparse\n================\n\nUnparser for Python 3 abstract syntax trees (ASTs) with type comments.\n\n.. image:: https://img.shields.io/pypi/v/typed-astunparse.svg\n    :target: https://pypi.org/project/typed-astunparse\n    :alt: package version from PyPI\n\n.. image:: https://travis-ci.org/mbdevpl/typed-astunparse.svg?branch=master\n    :target: https://travis-ci.org/mbdevpl/typed-astunparse\n    :alt: build status from Travis CI\n\n.. image:: https://ci.appveyor.com/api/projects/status/github/mbdevpl/typed-astunparse?svg=true\n    :target: https://ci.appveyor.com/project/mbdevpl/typed-astunparse\n    :alt: build status from AppVeyor\n\n.. image:: https://api.codacy.com/project/badge/Grade/4a6d141d87c346f0b3c0d50d76a10e32\n    :target: https://www.codacy.com/app/mbdevpl/typed-astunparse\n    :alt: grade from Codacy\n\n.. image:: https://codecov.io/gh/mbdevpl/typed-astunparse/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/mbdevpl/typed-astunparse\n    :alt: test coverage from Codecov\n\n.. image:: https://img.shields.io/github/license/mbdevpl/typed-astunparse.svg\n    :target: https://github.com/mbdevpl/typed-astunparse/blob/master/NOTICE\n    :alt: license\n\nThe *typed-astunparse* is to *typed-ast* as *astunparse* is to *ast*. In short: unparsing of Python\n3 abstract syntax trees (ASTs) with type comments.\n\n.. contents::\n    :backlinks: none\n\n\nWhy this module was created\n===========================\n\nThe built-in *ast* module can parse Python source code into AST but it can't generate source\ncode from the AST. The *astunparse* module (using a refactored version of an obscure\nscript found in official Python repository) provides code generation capability for native\nPython AST.\n\nHowever, both *ast* and *astunparse* modules completely ignore type comments introduced in\nPEP 484. They treat them like all other comments, so when you parse the code using\n:python:`compile()`, your type comments will be lost. There is no place for them in the AST, so\nobviously they also cannot be unparsed.\n\nThe *typed-ast* module provides an updated AST including type comments defined in PEP 484 and\na parser for Python code that contains such comments.\n\nUnfortunately, *typed-ast* doesn't provide any means to go from AST back to source code with type\ncomments. This is why module *typed-astunparse* (i.e. this one) was created: to provide unparser\nfor AST defined in *typed-ast*.\n\n\nUsage\n=====\n\nExample of roundtrip from code through AST to code:\n\n.. code:: python\n\n    import typed_ast.ast3\n    import typed_astunparse\n\n    code = 'my_string = None  # type: str'\n    roundtrip = typed_astunparse.unparse(typed_ast.ast3.parse(code))\n    print(roundtrip)\n\nThis will print:\n\n.. code:: python\n\n    my_string = None  # type: str\n\n\nfor more examples see `\u003cexamples.ipynb\u003e`_ notebook.\n\n\n\nInstallation\n============\n\nFor simplest installation use :bash:`pip`:\n\n.. code:: bash\n\n    pip3 install typed-astunparse\n\nYou can also build your own version:\n\n.. code:: bash\n\n    git clone https://github.com/mbdevpl/typed-astunparse\n    cd typed-astunparse\n    pip3 install -U test_requirements.txt\n    python3 -m unittest  # make sure the tests pass\n    python3 setup.py bdist_wheel\n    pip3 install dist/*.whl\n\n\nRequirements\n------------\n\nPython version 3.5 or later.\n\nPython libraries as specified in `\u003crequirements.txt\u003e`_.\n\nBuilding and running tests additionally requires packages listed in `\u003ctest_requirements.txt\u003e`_.\n\nTested on Linux, OS X and Windows.\n\n\nLinks\n=====\n\n\nExtensions of this module\n-------------------------\n\nIf you're extending typed-astunparse and you'd like to share why,\nfeel free to submit a `pull request \u003chttps://github.com/mbdevpl/typed-astunparse/pulls\u003e`_\nintroducing your project.\n\n-   *horast*: human-oriented ast\n\n    Built upon both *typed-ast* and *typed-astunparse* providing parsing and unparsing\n    of arbitrary comments in addition to type comments.\n\n    https://pypi.org/project/horast\n\n    https://github.com/mbdevpl/horast\n\n\nWho's using this module and why\n-------------------------------\n\nIf you're using typed-astunparse in your work and you'd like to share why,\nfeel free to submit a `pull request \u003chttps://github.com/mbdevpl/typed-astunparse/pulls\u003e`_\nintroducing your project.\n\n-   *static-typing*: using *typed-astunparse* directly to provide AST unparsing function\n\n    https://pypi.org/project/static-typing\n\n    https://github.com/mbdevpl/static-typing\n\n\nReferences\n----------\n\n-   *ast*:\n\n    https://docs.python.org/3/library/ast.html\n\n    https://greentreesnakes.readthedocs.io/\n\n-   *astunparse*:\n\n    https://pypi.org/project/astunparse\n\n    https://github.com/simonpercivall/astunparse\n\n    https://astunparse.readthedocs.io/en/latest/\n\n-   PEP 483 - The Theory of Type Hints:\n\n    https://www.python.org/dev/peps/pep-0483/\n\n-   PEP 484 - Type Hints:\n\n    https://www.python.org/dev/peps/pep-0484/\n\n-   PEP 3107 - Function Annotations:\n\n    https://www.python.org/dev/peps/pep-3107/\n\n-   PEP 526 - Syntax for Variable Annotations:\n\n    https://www.python.org/dev/peps/pep-0526/\n\n-   *typed-ast*:\n\n    https://pypi.org/project/typed-ast\n\n    https://github.com/python/typed_ast\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbdevpl%2Ftyped-astunparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbdevpl%2Ftyped-astunparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbdevpl%2Ftyped-astunparse/lists"}