Skip to main content

effit

Custom augmented-assignment syntax for Python. Write x scale= 2 instead of x = scale(x, 2).

License: MIT


What is effit?

effit introduces a custom syntax extension to Python: the function-assignment operator.

Instead of writing:

x = scale(x, 2)
my_list = append_items(my_list, [4, 5])
data = merge(data, {"b": 2})

You can write:

x scale= 2
my_list append_items= [4, 5]
data merge= {"b": 2}

The general pattern is:

<target> <function_name>= <arguments>

which transpiles to:

<target> = <function_name>(<target>, <arguments>)

Installation

pip install effit

For development:

git clone https://github.com/yoelAshkenazi/effit.git
cd effit
pip install -e ".[dev]"

Quick Start

  1. Activate the hook in your entry point (e.g., main.py):
import effit
effit.activate()

# Now you can import .eff files as regular modules
import my_module  # will find and transpile my_module.eff
  1. Write your .eff file (my_module.eff):
def scale(x, factor):
    return x * factor

def add(x, y):
    return x + y

x = 10
x scale= 2    # x is now 20
x add= 5      # x is now 25
print(x)       # prints 25

Option 2: Intercept .py files too

import effit
effit.activate(transpile_py=True)

# Now ALL .py imports are transpiled (adds slight overhead)

Option 3: Transpile and execute a string directly

import effit

source = """
def scale(x, factor):
    return x * factor

x = 10
x scale= 2
"""

ns = effit.run_string(source)
print(ns['x'])  # 20

Option 4: Just transpile (no execution)

import effit

code = "x scale= 2"
print(effit.transpile_line(code))
# Output: x = scale(x, 2)

source = """
x = 10
x scale= 2
y = [1, 2]
y extend_list= [3, 4]
"""
print(effit.transpile_source(source))
# Output:
# x = 10
# x = scale(x, 2)
# y = [1, 2]
# y = extend_list(y, [3, 4])

How It Works

The Syntax Pattern

<target> <function_name>= <arguments>
Component Description
<target> Any valid Python identifier, dotted name, or subscript
<function_name> A valid Python identifier (not a keyword)
= The assignment character (not ==)
<arguments> Everything remaining on the line — passed as 2nd+ args

Examples

Before (effit syntax) After (standard Python)
x scale= 2 x = scale(x, 2)
my_list append_items= [4, 5] my_list = append_items(my_list, [4, 5])
data merge= {"b": 2} data = merge(data, {"b": 2})
obj.attr transform= True obj.attr = transform(obj.attr, True)
arr[0] scale= 3 arr[0] = scale(arr[0], 3)

What is NOT matched (safety)

  • Standard assignments: x = 10
  • Augmented assignments: x += 1, x *= 2
  • Comparisons: if x == 2:
  • Patterns inside string literals: "x scale= 2"
  • Patterns inside comments: # x scale= 2
  • Python keywords as the function name: x return= 5

Architecture

effit/
├── __init__.py   — Public API (activate, deactivate, run_string, transpile_*)
├── parser.py     — Regex-based transpiler (transpile_line, transpile_source)
└── hook.py       — PEP 302 import hook (EffitFinder, EffitLoader)

The transpiler works in three stages:

  1. Mask — String literals and comments are replaced with opaque placeholders.
  2. Match — A regex identifies the target func= args pattern.
  3. Rewrite — The matched line is rewritten as target = func(target, args).
  4. Unmask — Original strings and comments are restored.

Running Tests

pip install -e ".[dev]"
pytest

With coverage:

pytest --cov=effit --cov-report=term-missing

Release files for effit 0.1.0

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

Source distribution (sdist)

Source distribution for effit 0.1.0
File Size Uploaded
effit-0.1.0.tar.gz 12.9 kB Details

Built distribution (wheel)

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

Total release size: 23.1 kB

Release files / effit-0.1.0.tar.gz

Download URL effit-0.1.0.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f7d25a043f6690ed18b965b1bc2f8fcc6f73a9182fb759cc2e05002b93f397b2
BLAKE2b-256 checksum
How to use checksums
57c76611a30878e69b8420e647ca446f0adf7c5c9729ac1cebc53403ee7ea24d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Release files / effit-0.1.0-py3-none-any.whl

Download URL effit-0.1.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfeda527c93b10d189ca54a45e96e4ab446a3213dc90f5248e18327462e05003
BLAKE2b-256 checksum
How to use checksums
7f407ab2e5436c0e2670f0eddb6ddc6a880232c5d8498c11df751b41a16a9171
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

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