fix the default arguments of mathutils.clamp #128
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
mathutils.clamp
is supposed to restrict an arbitrary number to the interval given by its last two (optional) arguments. But it is incorrect when not bothlower
andupper
arguments are givenThe default arguments are
None
, which isn't comparable in Python 3 and is less than x for any x in Python 2 (except NaN).clamp(1)
None
TypeError
1
clamp(1, upper=2)
1
TypeError
1
clamp(1, lower=0)
ValueError
TypeError
1
This fixes
mathutils.clamp
by simply using positive infinity and negative infinity as default bounds, and adds two test cases as well as an example in the function's docstring.