{"id":13800813,"url":"https://github.com/orsinium-labs/infer-types","last_synced_at":"2025-10-05T23:36:54.319Z","repository":{"id":65777847,"uuid":"522550019","full_name":"orsinium-labs/infer-types","owner":"orsinium-labs","description":"A CLI tool to automatically add type annotations into Python code. Must have tool for annotating existing code.","archived":false,"fork":false,"pushed_at":"2023-03-17T10:51:30.000Z","size":64,"stargazers_count":74,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-01T15:42:33.797Z","etag":null,"topics":["annotations","code-formatter","code-generation","mypy","pyannotate","python","python3","pytype","static-analysis","type-annotations","type-checking","type-inference","typing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"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/orsinium-labs.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}},"created_at":"2022-08-08T12:57:38.000Z","updated_at":"2024-04-21T20:15:24.000Z","dependencies_parsed_at":"2024-01-07T21:53:06.020Z","dependency_job_id":"d71632f4-641c-4400-abd2-ac41c9be20fe","html_url":"https://github.com/orsinium-labs/infer-types","commit_stats":{"total_commits":74,"total_committers":2,"mean_commits":37.0,"dds":0.1351351351351351,"last_synced_commit":"351199819f702414d832c3e2cc6c5b1c6ae5f6a1"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orsinium-labs%2Finfer-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orsinium-labs%2Finfer-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orsinium-labs%2Finfer-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orsinium-labs%2Finfer-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orsinium-labs","download_url":"https://codeload.github.com/orsinium-labs/infer-types/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249155899,"owners_count":21221674,"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","code-formatter","code-generation","mypy","pyannotate","python","python3","pytype","static-analysis","type-annotations","type-checking","type-inference","typing"],"created_at":"2024-08-04T00:01:16.507Z","updated_at":"2025-10-05T23:36:54.263Z","avatar_url":"https://github.com/orsinium-labs.png","language":"Python","funding_links":[],"categories":["Tools"],"sub_categories":["Helper tools to add annotations to existing code"],"readme":"# infer-types\n\nA CLI tool to automatically add type annotations into Python code.\n\nThe main scenario for using the tool is to help you with annotating a big and old codebase. It won't solve the task for you 100% but will definitely help you tremendously, because many of the functions in the real world have quite simple return types that are easy to infer automatically.\n\nFeatures:\n\n+ 100% automated, get a bunch of type annotations with no effort.\n+ 100% static, all types are inferred without running the code.\n+ A lot of heuristics and smart inference.\n+ Actively uses [typeshed](https://github.com/python/typeshed) to find annotations for unannotated dependencies.\n\n## Example\n\nLet's say, you have the following method:\n\n```python\nclass Database:\n    def users_count(self):\n        return len(self.users)\n```\n\nSince `len` always returns `int`, `infer-types` is able to infer the return type of the method. So, after running the tool, the code will look like this:\n\n```python\nclass Database:\n    def users_count(self) -\u003e int:\n        return len(self.users)\n```\n\n## Installation\n\n```bash\npython3 -m pip install infer-types\n```\n\n## Usage\n\n```bash\npython3 -m infer_types ./example/\n```\n\nThe tool will add new import statements that can be duplicated and are located not at the top of the file. To fix it, run [isort](https://github.com/PyCQA/isort):\n\n```bash\npython3 -m isort ./example/\n```\n\nThe infer-types tool uses the new fancy syntax for type annotations introduced in Python 3.10. So, instead of `Optional[str]` it will emit `str | None`. If your code is supposed to run on an older version of Python, add `from __future__ import annotations` at the beginning of each file. It will solve the issue and also make startup of your app faster. You can also do that with isort:\n\n```bash\npython3 -m isort --add-import 'from __future__ import annotations' ./example/\n```\n\nSee [awesome-python-typing](https://github.com/typeddjango/awesome-python-typing) for more tools to help you with annotating your code.\n\n## How it works\n\n+ Most of heuristics live in [astypes](https://github.com/orsinium-labs/astypes) package. Check it out learn more about the main inference logic.\n+ If the same method is defined in a base class, copy the type annotations from there.\n+ If there are no return statements returning a value, the return type is `None`.\n+ If there is a `yield` statement, the return type is `typing.Iterator`.\n+ In some cases, the return type can be guessed from the function name. For example, `is_open` function is assumed to return `bool` because it starts with `is_`.\n\nYou can run only a specific heuristic using the `--only` flag.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forsinium-labs%2Finfer-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forsinium-labs%2Finfer-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forsinium-labs%2Finfer-types/lists"}