Skip to main content

ideas

Ideas: making it easier to extend Python’s syntax.

ideas logo

Documentation

Everything you need can be found here. However, some of the documentation might be slightly out of date.

Installation

python -m pip install ideas

Depending on your OS, you might need to write python3 or py instead of python in the above.

Dependencies

  • token-utils
  • Python 3.8+ (Subject to change; it might work with older versions)

Usage

ideas -a my_cool_new_syntax my_program[.py]

Admitedly this is a bit terse ... Let's go into a bit more details.

Usage in more details

As a specific example of a new syntax, suppose that you want to use function as a keyword in Python, to mean the same thing as lambda, enabling you to write

# my_program.py

square = function x: x**2
print(f"{square(4)} is the square of 4.")

if __name__ == "__main__":
    print("This is run as the main module.")

You can do this using an import hook.

The simplest (but flawed) way to create such an import hook with ideas would be as follows:

from ideas import import_hook

def transform(source, **kwargs):
    return source.replace("function", "lambda")

import_hook.create_hook(transform_source=transform, name=__main__)

Then, you'd need to use it. Since there is already an example import hook that does this, we'll use it instead. All you have to do is instruct Python to add the import hook, and it will be used from that point on. There are two ways to do so.

The first method would be to create a second file which adds the required import hook and then imports your program.

# Let's call this 'loader.py'

from ideas.examples import function_keyword
function_keyword.add_hook()

import my_program

You could then run this second file the normal way.

python loader.py

So, my_program.py, and any other module that could be loaded by it would recognize that function is a valid alternative to lambda. However, using this method, loader would be the __main__ script, and the code block defined by if __name__ == "__main__": in my_program would be ignored.

The second way is to skip the creation of a loader, and run my_program directly using ideas:

ideas -a function_keyword my_program

This method will ensure that my_program is the __main__ module. In this example, ideas is an entry point for the project equivalent to writing py -m ideas.

Many more examples can be found in the documentation, including a better way to create such an import hook and information about a console (REPL) that supports code transformations.

Tools

This project uses black for formatting, pytest for running tests, and flake8 for linting with custom settings compatible with black.

License

MIT

Metadata

Release files for ideas 0.3.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ideas 0.3.10
File Size Uploaded
ideas-0.3.10.tar.gz 17.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for ideas 0.3.10
File Interpreter ABI Platform
ideas-0.3.10-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 MB

Release files / ideas-0.3.10.tar.gz

Download URL ideas-0.3.10.tar.gz
Size 17.8 MB
Tags Source
SHA-256 checksum
How to use checksums
db5ffbaef53c8a62dbb5ca3599d60a3fcb34661840bd23c638269e06cd2e5b65
BLAKE2b-256 checksum
How to use checksums
e49136f6ea91f839b76ad84b3571a9caa4786a19867b4355a78923a30f98f45b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / ideas-0.3.10-py3-none-any.whl

Download URL ideas-0.3.10-py3-none-any.whl
Size 74.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b75430f62646ebc26477f7151c7d918cca86554a548e587c7bedbca4afc6c9d
BLAKE2b-256 checksum
How to use checksums
64dca444241385064e792e141a481e4b84f87520b68eb5f084f817e3f99a5127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.3.10 This release

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.44

2 release files

0.0.42

2 release files

0.0.40

2 release files

0.0.39

2 release files

0.0.37

2 release files

0.0.36

2 release files

0.0.35

2 release files

0.0.33

2 release files

0.0.32

2 release files

0.0.31

2 release files

0.0.30

2 release files

0.0.29

2 release files

0.0.28

2 release files

0.0.27

2 release files

0.0.26

2 release files

0.0.25

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page