Skip to content

Commit ed4e968

Browse files
author
Sylvain MARIE
committed
Renamed _LambdaExpression into LambdaExpression
1 parent 1fa172c commit ed4e968

File tree

9 files changed

+88
-88
lines changed

9 files changed

+88
-88
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ The generated code contains functions that generate functions when called, such
2525

2626
```python
2727
def __gt__(self, other):
28-
""" Returns a new _LambdaExpression performing '<r> > other' on the result <r> of this evaluator's evaluation """
28+
""" Returns a new LambdaExpression performing '<r> > other' on the result <r> of this evaluator's evaluation """
2929
def ___gt__(input):
3030
# first evaluate the inner function
3131
r = self.evaluate(input)
3232
# then call the method
3333
return r > evaluate(other, input)
3434

35-
# return a new _LambdaExpression of the same type than self, with the new function as inner function
35+
# return a new LambdaExpression of the same type than self, with the new function as inner function
3636
return type(self)(___gt__)
3737
```
3838

code_generation/tpl_magic_methods.mako

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class _LambdaExpressionGenerated(_LambdaExpressionBase):
3737
% if o.uni_operator:
3838
## ----------unitary operator such as '-'-------------------
3939
def ${o.method_name}(self):
40-
""" Returns a new _LambdaExpression performing '${o.uni_operator}<r>' on the result <r> of this evaluator's evaluation """
40+
""" Returns a new LambdaExpression performing '${o.uni_operator}<r>' on the result <r> of this evaluator's evaluation """
4141
## def _${o.method_name}(r, input):
4242
## return ${o.uni_operator}r
4343
## return self.add_unbound_method_to_stack(_${o.method_name})
@@ -56,7 +56,7 @@ class _LambdaExpressionGenerated(_LambdaExpressionBase):
5656
% if o.is_operator_left:
5757
## --------pairwise operator - left---------------------
5858
def ${o.method_name}(self, other):
59-
""" Returns a new _LambdaExpression performing '<r> ${o.pair_operator} other' on the result <r> of this evaluator's evaluation """
59+
""" Returns a new LambdaExpression performing '<r> ${o.pair_operator} other' on the result <r> of this evaluator's evaluation """
6060
## def _${o.method_name}(r, input):
6161
## return r ${o.pair_operator} evaluate(other, input)
6262
## return self.add_unbound_method_to_stack(_${o.method_name})
@@ -76,7 +76,7 @@ class _LambdaExpressionGenerated(_LambdaExpressionBase):
7676
% else:
7777
## --------pairwise operator - right ---------------------
7878
def ${o.method_name}(self, other):
79-
""" Returns a new _LambdaExpression performing 'other ${o.pair_operator} <r>' on the result <r> of this evaluator's evaluation """
79+
""" Returns a new LambdaExpression performing 'other ${o.pair_operator} <r>' on the result <r> of this evaluator's evaluation """
8080
## def _${o.method_name}(r, input):
8181
## return evaluate(other, input) ${o.pair_operator} r
8282
## return self.add_unbound_method_to_stack(_${o.method_name})
@@ -97,7 +97,7 @@ class _LambdaExpressionGenerated(_LambdaExpressionBase):
9797
% elif o.unbound_method:
9898
## --------unbound method---------------------
9999
def ${o.method_name}(self, *args, **kwargs):
100-
""" Returns a new _LambdaExpression performing '${o.unbound_method.__name__}(<r>, *args, **kwargs)' on the result <r> of this evaluator's evaluation """
100+
""" Returns a new LambdaExpression performing '${o.unbound_method.__name__}(<r>, *args, **kwargs)' on the result <r> of this evaluator's evaluation """
101101
## def _${o.method_name}(r, input, *args, **kwargs):
102102
## return ${o.unbound_method.__name__}(r, input, *args, **kwargs)
103103
## return self.add_unbound_method_to_stack(_${o.method_name}, *args, **kwargs)
@@ -123,7 +123,7 @@ class _LambdaExpressionGenerated(_LambdaExpressionBase):
123123
% else:
124124
## --------general case---------------------
125125
def ${o.method_name}(self, *args, **kwargs):
126-
""" Returns a new _LambdaExpression performing '<r>.${o.method_name}(*args, **kwargs)' on the result <r> of this evaluator's evaluation """
126+
""" Returns a new LambdaExpression performing '<r>.${o.method_name}(*args, **kwargs)' on the result <r> of this evaluator's evaluation """
127127
# return self.add_bound_method_to_stack('${o.method_name}', *args, **kwargs)
128128
root_var, _ = _get_root_var(self, *args, **kwargs)
129129
def _${o.method_name}(input):
@@ -151,7 +151,7 @@ class _LambdaExpressionGenerated(_LambdaExpressionBase):
151151
% for o in to_override_with_exception:
152152
def ${o.method_name}(self, *args, **kwargs):
153153
"""
154-
This magic method can not be used on an _LambdaExpression, because unfortunately python checks the
154+
This magic method can not be used on an LambdaExpression, because unfortunately python checks the
155155
result type and does not allow it to be a custom type.
156156
"""
157157
raise FunctionDefinitionError('${o.method_name} is not supported by mini-lambda expressions, since python '

code_generation/tpl_magic_methods_replacements.mako

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ----
22
# This file is generated by mini_lambda_methods_generation.py - do not modify it !
33
# ----
4-
from mini_lambda.main import _LambdaExpression
4+
from mini_lambda.main import LambdaExpression
55
from sys import getsizeof
66

77
% if generate_all:
@@ -22,12 +22,12 @@ __all__ = [
2222

2323
% elif o.unbound_method:
2424
def ${o.module_method_name}(*args, **kwargs):
25-
""" This is a replacement method for _LambdaExpression '${o.method_name}' magic method """
25+
""" This is a replacement method for LambdaExpression '${o.method_name}' magic method """
2626
## return evaluator.add_unbound_method_to_stack(${o.unbound_method.__name__})
27-
return _LambdaExpression._get_expression_for_method_with_args(${o.unbound_method.__name__}, *args, **kwargs)
27+
return LambdaExpression._get_expression_for_method_with_args(${o.unbound_method.__name__}, *args, **kwargs)
2828
% else:
29-
def ${o.module_method_name}(expr: _LambdaExpression, *args, **kwargs):
30-
""" This is a replacement method for _LambdaExpression '${o.method_name}' magic method """
29+
def ${o.module_method_name}(expr: LambdaExpression, *args, **kwargs):
30+
""" This is a replacement method for LambdaExpression '${o.method_name}' magic method """
3131
return expr.add_bound_method_to_stack('${o.method_name}', *args, **kwargs)
3232
% endif
3333

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ So now
9898
```python
9999
>>> from mini_lambda import x
100100
>>> x ** 2
101-
<_LambdaExpression: x ** 2>
101+
<LambdaExpression: x ** 2>
102102
```
103103

104104
If you wish to bring back the old exception-raising behaviour, simply set the `repr_on` attribute of your expressions to `False`:
@@ -114,7 +114,7 @@ mini_lambda.base.FunctionDefinitionError: __repr__ is not supported by this Lamb
114114
## Main features
115115

116116
* More compact lambda expressions for single-variable functions
117-
* 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).
117+
* 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).
118118
* 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)
119119

120120

docs/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The simplest lambda expression is the variable itself. It is implemented with th
4141
from mini_lambda import x
4242

4343
# A variable is a lambda expression
44-
type(x) # <class 'mini_lambda.main._LambdaExpression'>
44+
type(x) # <class 'mini_lambda.main.LambdaExpression'>
4545

4646
# Evaluating the lambda expression applies the identity function
4747
x.evaluate(1234) # 1234
@@ -85,7 +85,7 @@ Indeed, `<expr>(input)` would create a new expression instead of evaluating it:
8585
result = my_first_expr(-1/2)
8686

8787
# still an expression !
88-
type(result) # <class 'mini_lambda.main._LambdaExpression'>
88+
type(result) # <class 'mini_lambda.main.LambdaExpression'>
8989
result.to_string() # "(2 * x + 1 > 0)(-0.5)"
9090
```
9191

@@ -176,7 +176,7 @@ expr = 'hello'[0:i] # fails
176176
expr = Get('hello', Slice(0, i)) # OK
177177
# representing: Repr/Str/Bytes/Sizeof/Hash
178178
# -- by default repr show the to_string()
179-
assert repr(l) == '<_LambdaExpression: l>'
179+
assert repr(l) == '<LambdaExpression: l>'
180180
# -- but you can disable it
181181
l.repr_on = False
182182
expr = repr(l) # fails

mini_lambda/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def evaluate(self, arg):
136136

137137
def __repr__(self):
138138
if self.repr_on:
139-
return "<_LambdaExpression: %s>" % self.to_string()
139+
return "<LambdaExpression: %s>" % self.to_string()
140140
else:
141141
raise FunctionDefinitionError('__repr__ is not supported by this Lambda Expression. If you wish to '
142142
'use `repr` in the lambda expression, use the replacement method `Repr`.'

0 commit comments

Comments
 (0)