Instead of `f.expr` and `f.variables[0]` try the following

```Python
var = Dummy()
expr = f(var)
```

This should work both for `SymPy.Lambda` and for Python functions.