[Biopython-dev] Bio.Restriction "super" call (Python vs PyPy?)

Eric Talevich eric.talevich at gmail.com
Sat Nov 26 03:00:04 UTC 2011


On Fri, Nov 25, 2011 at 8:24 PM, Brad Chapman <chapmanb at 50mail.com> wrote:

>
> Peter;
>
> > >> super(RestrictionType, cls).__init__(cls, name, bases, dct)
> > >
> > > That seems strange: the __init__ is calling super on itself. You'd
> > > normally expect this from a derived class. I'm not sure why this
> > > doesn't trigger an infinite recursion initializing the object. I'm +1
> > > on commenting it out.
>
> > I suppose we could be cautious and skip that line under PyPy
> > only. How about that as a compromise - that way if is really
> > is important for something not covered in the unit test, we only
> > break it under PyPy, but C Python and Jython would be fine?
>
> My vote would be to comment it out generally instead of if_pypy
> flags. I don't want to break anything, but if we do I'd rather find out
> straight away instead of chasing down platform specific bugs later. I'd
> be happy to hear other's opinions, especially if they ynderstand the
> super magic going on.
>
>
I support that, and maybe we can add some more unit tests to see if we can
find out what breaks, if anything.

Looking at the Bio/Restriction/Restriction.py, I can suggest these
candidates:

1. In the implementation of the class RestrictionType, a few of the magic
methods use the test "if isinstance(other, RestrictionType)" -- can you see
any way these might break without the super().__init__ call?


2. Other classes in the same file derive from RestrictionType, but don't
define their own __init__ methods (e.g. AbstractCut, and indirectly NoCut,
OneCut, etc.). All the methods seem to be class methods, also. (NB: maybe
use the @classmethod decorator everywhere for clarity.) As far as I can
tell, the unit test only uses class methods on EciRI, not any instance
methods -- if I'm reading that right, then maybe there should be a unit
test that hits that. This and #1 can be done at the same time with the
magic methods __add__, __ne__ and __gt__, for example.


3. In Bio/Restriction/__init__.py, I see this comment:

When testing for the presence of a Restriction enzyme in a
RestrictionBatch, the user can use:
1) a class of type 'RestrictionType'
2) a string of the name of the enzyme (it's repr)
i.e:
>>> from Bio.Restriction import RestrictionBatch, EcoRI
>>> MyBatch = RestrictionBatch(EcoRI)
>>> #!/usr/bin/env python
>>> EcoRI in MyBatch        # the class EcoRI.
True
>>>
>>> 'EcoRI' in MyBatch      # a string representation
True

I don't see this included in the unit test, test_Restriction.py. I don't
think the super().__init__ combo has anything to do with this feature, but
maybe it should be tested anyway, since it relies on some substantial magic.


-Eric



More information about the Biopython-dev mailing list