You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
!!! success "`repr` is now enabled by default for expressions! More details [here](#new-repr-now-enabled-by-default)"
8
+
7
9
This idea initially comes from the [valid8](https://smarie.github.io/python-valid8/) validation library. I ended up understanding that there were two complementary ways to provide users with easy-to-use validation functions:
8
10
9
11
* either to provide a very exhaustive catalog of functions to cover most use cases (is greater than, is between, etc.). *Drawback*: we need to reinvent all functions that exist already.
If you know python you should feel at home here, except for two things:
73
76
74
77
*`or` and `and` should be replaced with their bitwise equivalents `|` and `&`
75
-
* additional constants, methods and classes need to be made lambda-friendly before use. For convenience all of the [built-in functions](https://docs.python.org/3/library/functions.html) as well as constants, methods and classes from the `math.py` and `decimal.py` modules are provided in a lambda-friendly way by this package, hence the `from mini_lambda import Log` above.
78
+
* additional constants, methods and classes need to be made lambda-friendly before use. For convenience all of the [built-in functions](https://docs.python.org/3/library/functions.html) as well as constants, methods and classes from the `math.py` and `decimal.py` modules are provided in a lambda-friendly way by this package, hence the `from mini_lambda.symbols.math_ import Log` above.
76
79
77
80
Note that the printed version provides the minimal equivalent representation taking into account operator precedence. Hence `numeric_test_2` got rid of the useless parenthesis. This is **not** a mathematical simplification like in [SymPy](http://www.sympy.org/fr/), i.e. `x - x` will **not** be simplified to `0`.
78
81
@@ -84,11 +87,32 @@ There are of course a few limitations to `mini_lambda` as compared to full-flavo
84
87
85
88
Check the [Usage](./usage/) page for more details.
86
89
90
+
## New: `repr` now enabled by default
91
+
92
+
Starting in version 2.0.0, the representation of lambda expressions does not raise exceptions anymore by default. This behaviour was a pain for developers, and was only like this for the very rare occasions where `repr` was used in the expression.
93
+
94
+
So now
95
+
96
+
```python
97
+
>>>from mini_lambda import x
98
+
>>> x **2
99
+
<_LambdaExpression: x **2>
100
+
```
101
+
102
+
If you wish to bring back the old exception-raising behaviour, simply set the `repr_on` attribute of your expressions to `False`:
103
+
104
+
```python
105
+
>>>from mini_lambda import x
106
+
>>> x.repr_on =False
107
+
>>> x **2
108
+
(...)
109
+
mini_lambda.base.FunctionDefinitionError: __repr__isnot supported by this Lambda Expression. (...)
110
+
```
87
111
88
112
## Main features
89
113
90
114
* More compact lambda expressions for single-variable functions
91
-
* As close to python syntax as technically possible: the base type for lambda expressions in `mini_lambda`, `_LambdaExpression`, overrides all operators that can be overriden as of today in [python 3.6](https://docs.python.org/3/reference/datamodel.html). The remaining limits come from the language itself, for example chained comparisons and `and/or` are not supported as python casts the partial results to boolean to enable short-circuits. Details [here](./usage#lambda-expression-syntax).
115
+
* As close to python syntax as technically possible: the base type for lambda expressions in `mini_lambda`, `_LambdaExpression`, overrides all operators that can be overriden as of today in [python](https://docs.python.org/3/reference/datamodel.html). The remaining limits come from the language itself, for example chained comparisons and `and/or` are not supported as python casts the partial results to boolean to enable short-circuits. Details [here](./usage#lambda-expression-syntax).
92
116
* Printability: expressions can be turned to string representation in order to (hopefully) get interpretable messages more easily, for example when the expression is used in a [validation context](https://github.com/smarie/python-valid8)
0 commit comments