[Python-Dev] Issue 2986: difflib.SequenceMatcher is partly broken
Tim Peters
tim.peters at gmail.com
Wed Jul 14 22:40:54 CEST 2010
[Steven D'Aprano]
>> 4. I normally dislike global flags, but this is one time it might be
>> less-worse than the alternatives.
>>
>> Modify SequenceMatcher to test for the value of a global flag,
>> defaulting to False if it doesn't exist.
>> ...
>> The flag will only exist if the caller explicitly creates it:
>>
>> import difflib
>> difflib.disable_heuristic = True
>> ...
A module global is a non-starter for me (for all the usual reasons
about the potentially horrid sociopathic consequences of one piece of
an app changing behavior for the entire app - fine if it's a small app
wholly understood by the user, potential nightmares if it's a large
app nobody understands <0.3 wink>).
[Nick Coghlan]
> Why make it a global? A property on the SequenceMatcher object should
> be able to do the right thing.
> ...
The pragmatic drawback is that the heuristics we're trying to disable
typically execute _during_ SequenceMatcher instance construction.
That's why it makes most sense to convey the information to the
constructor. Setting a property after the instance is created is
typically too late (unless several other SequenceMatcher methods are
rewritten to delay analyzing the second sequence).
> A flag on the object rather than a per-call flag may actually be the
> better API here anyway.
The call in question here is the constructor (__init__), so there's no
real difference between "on the object" and "per call" in this case.
More information about the Python-Dev
mailing list