ifeval
Evaluate all if-statement predicates in a Python file and simplify the code by removing unreachable branches.
This tool parses a Python source file, evaluates constant if conditions (if f(x), if x is None, etc.), and rewrites the file to include only the branches that would execute.
Installation
Clone the repository and install with pip:
git clone https://gitlab.com/knvvv/ifeval.git
cd ifeval
pip install .
Usage
Dry run (default)
To preview changes without modifying the file:
ifeval path/to/your_script.py
It will print the diff showing what would be changed.
Apply changes
To actually rewrite the file in-place, add the --no-dry flag:
ifeval path/to/your_script.py --no-dry
Example
Given the following code:
print("Hello")
if True:
print("Keep this")
else:
print("Remove this")
ifeval simplifies it to:
print("Hello")
print("Keep this")
⚠️ A word of caution ⚠️
This package executes all the code from files being analyzed. Do not run it on untrusted or potentially malicious code, as it may lead to arbitrary code execution.
Metadata
Release files for ifeval 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ifeval-0.0.1.tar.gz | 4.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ifeval-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / ifeval-0.0.1.tar.gz
| Download URL | ifeval-0.0.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b2462f25eea7b51223af660029204e2a2b2049e445ec7d8129014fd66b405fcc
|
|
BLAKE2b-256 checksum How to use checksums |
cbbf771596e2500d8812a58cea37db1066a776925719afee2f5155b52b1a4db1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / ifeval-0.0.1-py3-none-any.whl
| Download URL | ifeval-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
26574e39f175b0457e1813d8a926703fa62267daa8d58360785217a5a2f129c2
|
|
BLAKE2b-256 checksum How to use checksums |
79c9fe488f5dbc0dd7358d3030ff6ade74ec3665f4e7815def03a70430214540
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|