Skip to content

Commit 95ff07b

Browse files
author
Sylvain MARIE
committed
Changed back the round strategy: now it is implemented as working in python 3+, and in python 2 users can use Round
1 parent 1c95712 commit 95ff07b

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

code_generation/mini_lambda_methods_generation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ def define_what_needs_to_be_written():
357357
to_override.add(Override('__pos__', uni_operator='+', precedence_level='_PRECEDENCE_POS_NEG_BITWISE_NOT'))
358358
to_override.add(Override('__abs__', unbound_method=abs))
359359
to_override.add(Override('__invert__', uni_operator='~', precedence_level='_PRECEDENCE_POS_NEG_BITWISE_NOT'))
360-
# requires __float__ in python 2: skip
361-
# to_override.add(Override('__round__', unbound_method=round))
360+
# requires __float__ in python 2 but we add it still
361+
to_override.add(Override('__round__', unbound_method=round))
362362

363363
# ** Boolean types **
364364
# .__and__, .__xor__, .__or__, __rand__, __rxor__, __ror__
@@ -370,7 +370,7 @@ def define_what_needs_to_be_written():
370370
to_override.add(Override('__trunc__', unbound_method=trunc))
371371
to_override.add(Override('__coerce__'))
372372
to_skip.update({'__index__'})
373-
to_override_with_exception.add(OverExc('__round__', unbound_method=round))
373+
# to_override_with_exception.add(OverExc('__round__', unbound_method=round))
374374
to_override_with_exception.add(OverExc('__int__', unbound_method=int))
375375
# OverExc('__long__', unbound_method=long),
376376
to_override_with_exception.add(OverExc('__float__', unbound_method=float))

mini_lambda/tests/test_mini_lambda.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,13 @@ def test_evaluator_maths():
618618

619619
x = InputVar('x', float)
620620

621-
# since in python 2 round calls float then we protect it entirely
622-
with pytest.raises(FunctionDefinitionError):
623-
round(x)
624-
assert Round(x).evaluate(5.5) == 6
621+
if sys.version_info < (3, 0):
622+
# since in python 2 round calls float then we protect it entirely
623+
with pytest.raises(FunctionDefinitionError):
624+
round(x)
625+
assert Round(x).evaluate(5.5) == 6
626+
else:
627+
assert round(x).evaluate(5.5) == 6
625628
assert trunc(x).evaluate(5.5) == 5
626629

627630
with pytest.raises(FunctionDefinitionError):

0 commit comments

Comments
 (0)