Metadata-Version: 2.4
Name: ifeval
Version: 0.0.1
Summary: Evaluate all if-statement predicates in a Python file
Home-page: https://gitlab.com/knvvv/ifeval
Author: Nikolai Krivoshchapov
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: libcst
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# 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:

```bash
git clone https://gitlab.com/knvvv/ifeval.git
cd ifeval
pip install .
```

## Usage

### Dry run (default)

To preview changes without modifying the file:

```bash
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:

```bash
ifeval path/to/your_script.py --no-dry
```

## Example
Given the following code:

```python
print("Hello")
if True:
    print("Keep this")
else:
    print("Remove this")
```

`ifeval` simplifies it to:

```python
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.
