{"id":13648352,"url":"https://github.com/ilevkivskyi/com2ann","last_synced_at":"2025-04-05T14:07:58.166Z","repository":{"id":12358452,"uuid":"67775941","full_name":"ilevkivskyi/com2ann","owner":"ilevkivskyi","description":"Tool for translation type comments to type annotations in Python","archived":false,"fork":false,"pushed_at":"2024-03-14T00:13:44.000Z","size":115,"stargazers_count":145,"open_issues_count":7,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T13:10:02.903Z","etag":null,"topics":["annotations","python-3-6","source-to-source","type-annotations","type-hints"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ilevkivskyi.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-09T07:17:02.000Z","updated_at":"2025-03-24T15:48:46.000Z","dependencies_parsed_at":"2022-07-11T19:54:37.283Z","dependency_job_id":"b7e1c1fa-8ece-4b36-9459-9b5bb3983437","html_url":"https://github.com/ilevkivskyi/com2ann","commit_stats":{"total_commits":38,"total_committers":5,"mean_commits":7.6,"dds":0.2894736842105263,"last_synced_commit":"b6fb21a75a6f6e7ef37f02ed2e9576b012acd5ba"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilevkivskyi%2Fcom2ann","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilevkivskyi%2Fcom2ann/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilevkivskyi%2Fcom2ann/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilevkivskyi%2Fcom2ann/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ilevkivskyi","download_url":"https://codeload.github.com/ilevkivskyi/com2ann/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345853,"owners_count":20924102,"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":["annotations","python-3-6","source-to-source","type-annotations","type-hints"],"created_at":"2024-08-02T01:04:10.219Z","updated_at":"2025-04-05T14:07:58.148Z","avatar_url":"https://github.com/ilevkivskyi.png","language":"Python","readme":"com2ann\n=======\n\n[![Build Status](https://travis-ci.org/ilevkivskyi/com2ann.svg)](https://travis-ci.org/ilevkivskyi/com2ann)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n\nTool for translation of type comments to type annotations in Python.\n\nThe tool requires Python 3.8 to run. But the supported target code version\nis Python 3.4+ (can be specified with `--python-minor-version`).\n\nCurrently, the tool translates function and assignment type comments to\ntype annotations. For example this code:\n```python\nfrom typing import Optional, Final\n\nMAX_LEVEL = 80  # type: Final\n\nclass Template:\n    default = None  # type: Optional[str]\n\n    def apply(self, value, **opts):\n        # type: (str, **bool) -\u003e str\n        ...\n```\nwill be translated to:\n```python\nfrom typing import Optional, Final\n\nMAX_LEVEL: Final = 80\n\nclass Template:\n    default: Optional[str] = None\n\n    def apply(self, value: str, **opts: bool) -\u003e str:\n        ...\n```\n\nThe philosophy of the tool is to be minimally invasive, and preserve original\nformatting as much as possible. This is why the tool doesn't use un-parse.\n\nThe only (optional) formatting code modification is wrapping long function\nsignatures. To specify the maximal length, use `--wrap-signatures MAX_LENGTH`.\nThe signatures are wrapped one argument per line (after each comma), for example:\n```python\n    def apply(self,\n              value: str,\n              **opts: bool) -\u003e str:\n        ...\n```\n\nFor working with stubs, there are two additional options for assignments:\n`--drop-ellipsis` and `--drop-none`. They will result in omitting the redundant\nright hand sides. For example, this:\n```python\nvar = ...  # type: List[int]\nclass Test:\n    attr = None  # type: str\n```\nwill be translated with such options to:\n```python\nvar: List[int]\nclass Test:\n    attr: str\n```\n### Usage\n$ `com2ann --help`\n```\nusage: com2ann [-h] [-o OUTFILE] [-s] [-n] [-e] [-i] [-w WRAP_SIGNATURES]\n               [-v PYTHON_MINOR_VERSION]\n               infile\n\nHelper module to translate type comments to type annotations. The key idea of\nthis module is to perform the translation while preserving the original\nformatting as much as possible. We try to be not opinionated about code\nformatting and therefore work at the source code and tokenizer level instead\nof modifying AST and using un-parse. We are especially careful about\nassignment statements, and keep the placement of additional (non-type)\ncomments. For function definitions, we might introduce some formatting\nmodifications, if the original formatting was too tricky.\n\npositional arguments:\n  infile                input file or directory for translation, must contain\n                        no syntax errors; if --outfile is not given,\n                        translation is made *in place*\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -o OUTFILE, --outfile OUTFILE\n                        output file or directory, will be overwritten if\n                        exists, defaults to input file or directory\n  -s, --silent          do not print summary for line numbers of translated\n                        and rejected comments\n  -n, --drop-none       drop any None as assignment value during translation\n                        if it is annotated by a type comment\n  -e, --drop-ellipsis   drop any Ellipsis (...) as assignment value during\n                        translation if it is annotated by a type comment\n  -i, --add-future-imports\n                        add 'from __future__ import annotations' to any file\n                        where type comments were successfully translated\n  -w WRAP_SIGNATURES, --wrap-signatures WRAP_SIGNATURES\n                        wrap function headers that are longer than given\n                        length\n  -v PYTHON_MINOR_VERSION, --python-minor-version PYTHON_MINOR_VERSION\n                        Python 3 minor version to use to parse the files\n```\n","funding_links":[],"categories":["Python","Python - BE in general","Upgrading tools","Code Refactoring","Tools"],"sub_categories":["type annotations","Working with types"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filevkivskyi%2Fcom2ann","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filevkivskyi%2Fcom2ann","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filevkivskyi%2Fcom2ann/lists"}