{"id":16715444,"url":"https://github.com/philippeitis/swytch","last_synced_at":"2025-03-15T08:43:00.933Z","repository":{"id":111799932,"uuid":"252627282","full_name":"philippeitis/swytch","owner":"philippeitis","description":"Yet another switch-case implementation in Python.","archived":false,"fork":false,"pushed_at":"2020-08-11T19:10:31.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-21T23:34:07.581Z","etag":null,"topics":[],"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/philippeitis.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":"2020-04-03T03:52:55.000Z","updated_at":"2020-08-11T19:10:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"51a0c3ed-f4c2-4e57-b896-3c691c774591","html_url":"https://github.com/philippeitis/swytch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philippeitis%2Fswytch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philippeitis%2Fswytch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philippeitis%2Fswytch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philippeitis%2Fswytch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/philippeitis","download_url":"https://codeload.github.com/philippeitis/swytch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243707302,"owners_count":20334615,"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-10-12T21:09:25.439Z","updated_at":"2025-03-15T08:43:00.913Z","avatar_url":"https://github.com/philippeitis.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swytch\nIf you've ever felt like you really, really need a switch statement in Python, then this might be the thing for you.\n\nThere's a little bit of everything for everyone: Exhaustive switches, default cases, switch cases for hashable types, switch cases for unhashable types, context-based switches, and switches over enums.\n\n```python\nimport enum\nfrom xswitch import case, Default, ExhaustiveSwitch\nclass PowersOfTwo(enum.IntEnum):\n  zero = 1\n  one = 2\n  two = 4\n  \nclass PowersOfTwoSwitch(ExhaustiveSwitch, enum=PowersOfTwo):\n  @case(PowersOfTwo.zero)\n  def zero(self):\n    print(\"2^0\")\n  \n  @case(PowersOfTwo.one)\n  def one(self):\n    print(\"2^one\")\n  \n  @case(Default)\n  def default(self):\n    print(\"2^?\")\n\nif __name__ == \"__main__\":\n  PowersOfTwoSwitch.match(0)\n  PowersOfTwoSwitch.match(PowersOfTwo.one)\n  PowersOfTwoSwitch.match(5)\n\n\u003e\u003e\u003e 2^0\n\u003e\u003e\u003e 2^one\n\u003e\u003e\u003e 2^?\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilippeitis%2Fswytch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphilippeitis%2Fswytch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilippeitis%2Fswytch/lists"}