[Biopython-dev] Bio.Motif length

Peter biopython at maubp.freeserve.co.uk
Wed Oct 27 11:03:15 UTC 2010


On Wed, Oct 27, 2010 at 11:53 AM, Bartek Wilczynski <barwil at gmail.com> wrote:
> Hi Peter,
>
> On Wed, Oct 27, 2010 at 12:34 PM, Peter <biopython at maubp.freeserve.co.uk>wrote:
>
>>
>> Why do you have motif.length when len(motif) seems to do
>> basically the same thing? Can we deprecate the length
>> property (Zen of Python: There should be one -- and
>> preferably only one -- obvious way to do it)?
>>
>
> I guess this is there just out of habit. I know that the .length property
> and I tend to use it, but I agree that in the tutorial we should use len(m)
> instead of m.length.
>
> Speaking more globally, the length property is there from the beginning, I
> don't think we should remove it. If we really want to make the API clean, we
> could rename it to m._length to indicate that it should not be used directly
> (especially setting it to some other value could have unwanted
> consequences).
>
> I can make the change in the tutorial (I need to change the expected output
> of m.format("fasta") anyway), but making the change from .length to ._length
> in the code would require a bit more time to make sure I'm not using it
> anywhere in the code. What is your suggestion here?

What I would suggest is right now:

(1) Use len(...) in the tutorial and any docstrings. Also in the
__len__ docstring you could mention that using the .length
property is discouraged.

Then later as your time permits,

(2) Rename self.length to self._length throughout the code, check
tests pass
(3) Add a property length which acts as a proxy for self._length
and say in the docstring that you encourage len(...) instead.
This is to ensure existing code using .length still works.

Then later,

(4) Add a deprecation warning to the new length property.

One year and two releases later:

(5) Remove the length property (leaving the private _length
property only).

Peter



More information about the Biopython-dev mailing list