views:

325

answers:

4

In this file, in the function cross_from_below(x, threshold), there is a line that says threshold = threshold. What's the point of this line? Does this do something differently than if this command weren't there?

+14  A: 

There is no point to that assignment. It's probably just left over and should be removed. The next function is nearly identical, and doesn't have it.

Ned Batchelder
Esp since the function cross_from_above, right below it, follows a similar pattern but does not have the threshold = threshold assignment.
Jarret Hardie
+3  A: 

It could mean something. For example, if threshold was a property of a class, then assigning it could call a setter method.

But in this case, I think it's a typo. I've looked at the changelog and there is no hint that this was intentional for any reason.

Aaron Digulla
+7  A: 

No, in the specific example you quote, that line is (harmless but) redundant -- indeed the very next function (cross threshold from above rather than from below) is almost identical (save of course for the direction of the comparisons), lacks that extra assignment, yet works just the same way.

The one and only case where something like threshold=threshold would make a difference is in a def statement, where it's the idiom to force early binding of a name (it makes use of the fact that default values are evaluated at def time, i.e., "early";-). But that's not what that code is doing -- just adding it for completeness.

Alex Martelli
+1  A: 

Or it could be one of those cases where it made sense at some point to write something like :

 self.threshold = threshold

because the function was a method of some class that needed to kept the threshold. (In which case, it would mean something else, wouldn't it ?)

phtrivier
which is what aaron just said. Sorry.
phtrivier