{"id":13771157,"url":"https://github.com/Kludex/no-optional","last_synced_at":"2025-05-11T03:33:06.378Z","repository":{"id":37000525,"uuid":"503213018","full_name":"Kludex/no-optional","owner":"Kludex","description":"Replace `Optional[T]` by `Union[T, None]` 👀","archived":false,"fork":false,"pushed_at":"2022-06-25T06:38:39.000Z","size":25,"stargazers_count":57,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-14T21:52:52.889Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/Kludex.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":"2022-06-14T04:53:33.000Z","updated_at":"2025-02-14T22:09:59.000Z","dependencies_parsed_at":"2022-06-29T07:11:18.204Z","dependency_job_id":null,"html_url":"https://github.com/Kludex/no-optional","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kludex%2Fno-optional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kludex%2Fno-optional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kludex%2Fno-optional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kludex%2Fno-optional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kludex","download_url":"https://codeload.github.com/Kludex/no-optional/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253514352,"owners_count":21920327,"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-03T17:00:48.418Z","updated_at":"2025-05-11T03:33:06.075Z","avatar_url":"https://github.com/Kludex.png","language":"Python","readme":"\u003ch1 align=\"center\"\u003e\n    \u003cstrong\u003eno-optional\u003c/strong\u003e\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://pypi.org/project/no-optional\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/v/no-optional\" alt=\"Package version\"\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/pyversions/no-optional\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/Kludex/no-optional\"\u003e\n\u003c/p\u003e\n\nThis [codemod](https://libcst.readthedocs.io/en/stable/codemods_tutorial.html) replaces `typing.Optional[T]` by `typing.Union[T, None]` in the codebase.\n\n## Why?\n\nThis tool was inspired by a tweet from [Sebastián Ramírez](https://twitter.com/tiangolo) (as you see below), and a conversation between us.\n\n\u003cimg width=\"599\" alt=\"image\" src=\"https://user-images.githubusercontent.com/7353520/173566552-6759f21e-e0d2-4bb6-9a7a-bac7c360e7fe.png\"\u003e\n\nAs the tweet says, we have two reasons for doing this:\n\n1. It's more explicit to write `Union[str, None]` than `Optional[str]`. Mainly because `Optional[str]` doesn't mean that the attribute is optional.\nIt only means that it accepts `None` as a possible value.\n2. On Python 3.10+ you can type annotate as `str | None` instead of the above two. Which is more similar to `Union[str, None]` than `Optional[str]`.\n\n## Alternative\n\n[`pyupgrade`](https://github.com/asottile/pyupgrade) is great but `no-optional` is better when you need runtime support like for `FastAPI` and `pydantic`.\n\nThe reason being that `no-optional` just does the replacement. On the other hand, `pyupgrade` requires [`from __future__ import annotations`](https://peps.python.org/pep-0563/) for versions below Python 3.10.\n\n## Installation\n\n```bash\npip install no-optional\n```\n\n## Usage\n\nRun the following on the repository you want to format:\n\n```bash\npython -m no_optional \u003cfiles\u003e\n```\n\nYou can also use the pre-commit. Add the following to your `.pre-commit-config.yaml` file:\n\n```yaml\n  - repo: https://github.com/Kludex/no-optional\n    rev: 0.4.0\n    hooks:\n      - id: no_optional\n```\n\n## License\n\nThis project is licensed under the terms of the MIT license.\n","funding_links":[],"categories":["UNIX-way formatters"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKludex%2Fno-optional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKludex%2Fno-optional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKludex%2Fno-optional/lists"}