{"id":13800961,"url":"https://github.com/Luttik/auto-optional","last_synced_at":"2025-05-13T10:30:49.419Z","repository":{"id":44931884,"uuid":"401387202","full_name":"Luttik/auto-optional","owner":"Luttik","description":"Makes typed arguments Optional when the default argument is None","archived":false,"fork":false,"pushed_at":"2022-12-09T13:53:18.000Z","size":599,"stargazers_count":17,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-10T05:41:57.834Z","etag":null,"topics":["code-quality","pypi","python","python3","refactoring"],"latest_commit_sha":null,"homepage":"https://auto-optional.daanluttik.nl/","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/Luttik.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}},"created_at":"2021-08-30T15:09:10.000Z","updated_at":"2024-10-23T02:12:24.000Z","dependencies_parsed_at":"2023-01-25T22:01:38.400Z","dependency_job_id":null,"html_url":"https://github.com/Luttik/auto-optional","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luttik%2Fauto-optional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luttik%2Fauto-optional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luttik%2Fauto-optional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luttik%2Fauto-optional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Luttik","download_url":"https://codeload.github.com/Luttik/auto-optional/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225198953,"owners_count":17437004,"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":["code-quality","pypi","python","python3","refactoring"],"created_at":"2024-08-04T00:01:18.059Z","updated_at":"2024-11-18T15:31:25.541Z","avatar_url":"https://github.com/Luttik.png","language":"Python","readme":"# auto-optional\n\u003cimg src=\"https://raw.githubusercontent.com/Luttik/auto-optional/main/docs/assets/images/logo-with-text.svg\" style=\"width: 100%; margin: 32pt 0\" alt=\"Logo\"\u003e\n\n\n\u003cp align=\"center\"\u003e\n    auto-optional: adds the Optional type-hint to arguments where the default value is None\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/Luttik/auto-optional/actions?query=workflow%3ACI+branch%3Amaster\"\u003e\n        \u003cimg src=\"https://github.com/luttik/auto-optional/workflows/CI/badge.svg\" alt=\"actions batch\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/auto-optional/\"\u003e\n        \u003cimg src=\"https://badge.fury.io/py/auto-optional.svg\" alt=\"pypi\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/auto-optional/\"\u003e\n        \u003cimg src=\"https://shields.io/pypi/pyversions/auto-optional\" alt=\"python versions\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/luttik/auto-optional\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/Luttik/auto-optional/branch/main/graph/badge.svg\" alt=\"codecov\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/Luttik/auto-optional/blob/main/LICENSE\"\u003e\n        \u003cimg src=\"https://shields.io/github/license/luttik/auto-optional\" alt=\"License: MIT\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/psf/black\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"Code style: black\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n**Documentation**: [auto-optional.daanluttik.nl](https://auto-optional.daanluttik.nl)\n\n**Source Code**: [github.com/luttik/auto-optional](https://github.com/Luttik/auto-optional) \n\n---\n\n## What does auto-optional do\nThe basic purpose of auto-optional is ensuring that whenever a default argument is `None` the type annotation is Optional.\n\nFor example:\n```py\ndef foo(bar: str = None):\n    ...\n```\n\nWould turn into\n\n```py\nfrom typing import Optional\ndef foo(bar: Optional[str] = None):\n    ...\n```\n\n## Why would you want this\n\n- Easily modify external libraries that didn't pay attention \n  to proper use of optional to improve mypy lintingf.\n- Force consistency in your own code-base: \n  Enforcing that `None` parameter implies an `Optional` type. \n- Explicit is better than implicit — [pep 20](https://www.python.org/dev/peps/pep-0020/)\n\n## In the media:\nauto-optional was covered on \n[PythonBytes #251](https://pythonbytes.fm/episodes/show/251/a-95-complete-episode-wait-for-it)\n\n\u003e I love these little tools that you can run against your code that will just reformat them to be better.\n\u003e\n\u003e — Michael Kennedy\n\n## Install\nInstall with `pip install auto-optional`.\n\n## Run\nAfter installing you can run auto-optional using `auto-optional [paths...]`\n(if no path is provided it'll process the current working directory).\n\n## pre-commit\n\nYou can run auto-optional via [pre-commit](https://pre-commit.com/).\nAdd the following text to your repositories `.pre-commit-config.yaml`:\n\n```yaml\nrepos:\n- repo: https://github.com/luttik/auto-optional\n  rev: v0.3.1 # The version of auto-optional to use\n  hooks:\n  - id: auto-optional\n```\n\n## Things of note\n\n### Things that are handled well\n\n- The alternatives to `Optional` are supported, that means both;\n    - `Union[X, None]`\n    - `x | None` (allowed since python 3.10+).\n- Existing imports are reused.\n    - `import as` and `from typing import ...` statements are properly handled.\n\n### Things that need improvement\nFor all these points you can leave a thumbs-up if you want it. Also, I welcome pull-requests for these issues.\n\n- There is no exclude (for file patterns) option yet [[#2]](https://github.com/Luttik/auto-optional/issues/2)\n- There is no ignore (for code lines) option yet [[#3]](https://github.com/Luttik/auto-optional/issues/3)\n- Code is aways read and written as `UTF-8` (which is accurate most of the time). [[#4]](https://github.com/Luttik/auto-optional/issues/4)\n- There is no `diff` or `check` command yet for a dry-run or linting. [[#5]](https://github.com/Luttik/auto-optional/issues/5)\n","funding_links":[],"categories":["Tools"],"sub_categories":["Helper tools to add annotations to existing code"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLuttik%2Fauto-optional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLuttik%2Fauto-optional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLuttik%2Fauto-optional/lists"}