{"id":13678229,"url":"https://github.com/aroberge/ideas","last_synced_at":"2025-12-24T06:41:56.239Z","repository":{"id":39846108,"uuid":"234971532","full_name":"aroberge/ideas","owner":"aroberge","description":"Easy creation of custom import hooks to experiment on alternatives to Python's syntax; see https://aroberge.github.io/ideas/docs/html/","archived":false,"fork":false,"pushed_at":"2023-12-10T11:33:58.000Z","size":17595,"stargazers_count":74,"open_issues_count":23,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-03-14T19:33:42.180Z","etag":null,"topics":["hook","import-hook","import-hooks","importlib","python","python-ideas"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aroberge.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-01-19T21:35:18.000Z","updated_at":"2024-05-27T16:48:12.039Z","dependencies_parsed_at":"2023-12-10T12:39:27.054Z","dependency_job_id":null,"html_url":"https://github.com/aroberge/ideas","commit_stats":{"total_commits":230,"total_committers":4,"mean_commits":57.5,"dds":0.05217391304347829,"last_synced_commit":"a53810451d9daeff986edcbb2e2f0921025a4d62"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aroberge%2Fideas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aroberge%2Fideas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aroberge%2Fideas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aroberge%2Fideas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aroberge","download_url":"https://codeload.github.com/aroberge/ideas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223603659,"owners_count":17172137,"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":["hook","import-hook","import-hooks","importlib","python","python-ideas"],"created_at":"2024-08-02T13:00:51.320Z","updated_at":"2025-12-24T06:41:56.203Z","avatar_url":"https://github.com/aroberge.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# ideas\n\n## *Ideas: making it easier to extend Python’s syntax.*\n\n![ideas logo](https://raw.githubusercontent.com/aroberge/ideas/master/ideas.png)\n\n\n## Documentation\n\n[Everything you need will eventually be found here](https://aroberge.github.io/ideas/docs/html/).\n\n## Installation\n\n```\npython -m pip install ideas\n```\n\nDepending on your OS, you might need to write `python3` or `py` instead of `python` in the above.\n\n## Dependencies\n\n - [token-utils](https://github.com/aroberge/token-utils)\n - Python 3.6+\n\nSome examples, using custom encoding, bytecode transformations or\nAST transformations do not work with Python 3.8 and/or later versions.\nHowever, they could be adapted to work with these later versions.\n\n## Usage\n\nSuppose that you want to use `function` as a keyword in Python, to mean\nthe same thing as `lambda`, enabling you to write\n\n```python\n# my_program.py\n\nsquare = function x: x**2\nprint(f\"{square(4)} is the square of 4.\")\n\nif __name__ == \"__main__\":\n    print(\"This is run as the main module.\")\n```\n\nYou can do this using an import hook.\n\nThe simplest (but flawed) way to create such an import hook with `ideas`\nwould be as follows:\n\n```python\nfrom ideas import import_hook\n\ndef transform(source, **kwargs):\n    return source.replace(\"function\", \"lambda\")\n\nimport_hook.create_hook(transform_source=transform)\n```\n\nThen, you'd need to use it. Since there is already an example import hook\nthat does this, we'll use it instead.  All you have to do\nis instruct Python to add the import hook, and it will be used\nfrom that point on. There are two ways to do so.\n\nThe first method would be to create a second file which adds the\nrequired import hook and then imports your program.\n\n```python\n# Let's call this 'loader.py'\n\nfrom ideas.examples import function_keyword\nfunction_keyword.add_hook()\n\nimport my_program\n```\n\nYou could then run this second file the normal way.\n\n```\npython loader.py\n```\n\nSo, `my_program.py` , and any other module that could be\nloaded by it would recognize that `function` is a valid alternative to `lambda`.\nHowever, using this method, `loader` would be the `__main__` script, and\nthe code block defined by `if __name__ == \"__main__\":` in `my_program`\nwould be ignored.\n\nThe second way is to skip the creation of a loader, and run `my_program` directly\nusing `ideas`:\n\n```\npython -m ideas my_program -t function_keyword\n```\nThis method will ensure that `my_program` is the `__main__` module.\n\nMany more examples can be found in the [documentation](https://aroberge.github.io/ideas/docs/html/),\nincluding a better way to create such an import hook and information about\na console (REPL) that supports code transformations.\n\n\n## Tools\n\nThis project uses [black](https://black.readthedocs.io/en/stable/) for formatting,\n[pytest](https://docs.pytest.org/en/latest/) for running tests,\nand [flake8](https://flake8.pycqa.org/en/latest/) for linting with custom\nsettings compatible with black.\n\n## Contact\n\nYou can either file an issue or email me at \u003cAndre.Roberge@gmail.com\u003e.\n\n\n## License\n\nMIT\n\n\n## Infrequently asked questions, comments and answers\n\nAs I write (and occasionally update) this README file, nobody else knows\nabout this project. So, it is impossible for there to be some Frequently Asked\nQuestions.  In their absence, the following imaginary dialogue has been written.\n\n\u003e _Why?_\n\nBecause it is fun. If this is not enough of a justification for you, have a look at\n[motivation](https://aroberge.github.io/ideas/docs/html/motivation.html)\nwhich contains a longer, and possibly more serious answer.\n\n\u003e _Is it safe to use in production code?_\n\nMost probably not.\n\n\u003e _But your example works perfectly well in my code; can I use it in my\n\u003e project?_\n\nI don't think you should if your project is to be used by anyone else\nbut yourself.\n\n\u003e _I found a bug._\n\nWonderful, please file an issue so that I can attempt to fix it. Note however\nthat some examples are just proof of concepts and are not meant to be robust.\n\n\u003e _Can I contribute code for a new example?_\n\nYes, please, by all means. But I suggest that you first create an issue that gives\nan overview of what you wish to accomplish.\n\n\u003e _I found a cool use of import hooks in another project, different from\n\u003e all of your examples. Could you include it?_\n\nPlease, give me the details, and I will see if I can **easily** include\na similar example and if I think it is worthwhile to do so.\n\n\u003e _I think that the explanation you have written for X could be improved upon._\n\nPlease tell me more by filing an issue first and possibly creating a pull-request afterwards.\n\n\u003e _I have an idea for a new example, but do not know how to write the code for it._\n\nFirst, make sure you go through all the existing examples to confirm that\nnone can easily be adapted to do what you want.\nIf that is the case, file an issue ...\nbut please don't be offended if I don't write code for it\nand end up closing the issue: I already have too many ideas of my own\nfor this project, too many other projects, and not\nenough time to do all that I want.\n\nThat being said, I do like tinkering with import hooks ...\n\n\u003e _In file X.py, you do not respect convention Y from PEP-8. This is unacceptable\n\u003e in a Python project._\n\n**Seriously?**  This project is all about exploring potential changes\nto Python's syntax, some of which are downright crazy, and you complain\nabout a PEP-8 violation? ...\n\nOk, perhaps you can tell me, and I will see if it makes sense to change what I wrote.\n\n\u003e _People from the Python-ideas mailing lists mentioned that I should look\n\u003e at this project for my idea, but I don't know where to start._\n\nPlease, have a look at the [documentation](https://aroberge.github.io/ideas/docs/html/).\nIf you go through all the examples in the order that they are presented, you\nmight learn how to implement your idea.\n\n\u003e What about something like `from __future__ import braces`?\n\n**No.** See [Examples that will never be included](https://aroberge.github.io/ideas/docs/html/excluded.html).\n\n\u003e _You're no fun. Anyway, why this silly name for a project?\n\u003e The word \"ideas\" has nothing to do with import hooks in Python._\n\nFor this project, I was thinking of using `importhook` (singular) or\n`importhooks` (plural). However, there is already a project named\n`importhook` on Pypi and I thought that using the plural form would\nlikely be just too confusing.\n\nI settled on `ideas` as I am guessing that the main application would be\nfor people to try out suggestions from or for\n[python-ideas](https://mail.python.org/archives/list/python-ideas@python.org/).\nA few days later, I came up with the above image and this cemented my\nhighly subjective opinion that this choice of name might not such a bad idea.\n\nAnyway, enough of this banter. If you want to know more about this project,\nplease consult the [documentation](https://aroberge.github.io/ideas/docs/html/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faroberge%2Fideas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faroberge%2Fideas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faroberge%2Fideas/lists"}