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

Release files for ideas 0.3.5

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.5
File Size Uploaded
ideas-0.3.5.tar.gz 17.8 MB Details

Built distribution (wheel)

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

Total release size: 17.9 MB

Release files / ideas-0.3.5.tar.gz

Download URL ideas-0.3.5.tar.gz
Size 17.8 MB
Tags Source
SHA-256 checksum
How to use checksums
4388b8114d1b0e177c01686d59b03e57d80db4ad8c5e01285ebaf0a0651ef584
BLAKE2b-256 checksum
How to use checksums
d89d94bb1d3e8bd6d54bda0d5a65cdbb44e873dfa306db84900c7be74d81a239
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.5-py3-none-any.whl

Download URL ideas-0.3.5-py3-none-any.whl
Size 74.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94e5f4e60dc44cc0b85594fe179b4eabee882075c4fdaaee1185d8e155c376e0
BLAKE2b-256 checksum
How to use checksums
1ad6d2db5da1d011b06837d4c4c7c4b13150064f1a39696704d4c8ac94620bce
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

0.3.7

2 release files

This release

0.3.5 This release

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