You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SeqFeature.WithinPosition instances fail to unpickle #2207
I am reporting a problem with Biopython version, Python version, and operating
system as follows:
3.6.6 (default, Jan 26 2019, 16:53:05)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
CPython
Linux-3.10.0-693.21.1.el7.x86_64-x86_64-with-centos-7.2.1511-Core
1.74
Expected behaviour
Instances of WithinPosition should pickle and unpickle
Actual behaviour
Unpickling a WithinPosition instance fails with:
TypeError Traceback (most recent call last)
in
4 wp = SeqFeature.WithinPosition(10,10,13)
5 p = pickle.dumps(wp)
----> 6 unpickled_wp = pickle.loads(p)
TypeError: __new__() missing 2 required positional arguments: 'left' and 'right'
Steps to reproduce
I ran into this unpickling an object containing a SeqRecord derived from UniProt acc P08514, but some digging narrowed it down to:
import pickle
from Bio import SeqFeature
wp = SeqFeature.WithinPosition(10,10,13)
p = pickle.dumps(wp)
unpickled_wp = pickle.loads(p)
Pickle expects __getnewargs__() or __getnewargs_ex__() to be defined for instances of classes that alter the call signature of __new__(cls). I assume WithinPosition inherits __getnewargs__() from int, but then overrides the __new__ signature so the two are not compatible. It looks as if several other *Position classes in this module will fail in the same way
Do you know enough about pickle to fix this and add a couple of unit tests, e.g. to Tests/test_SeqFeature.py for the positions, and perhaps also higher level in Tests/test_SeqRecord.py?
You can see a test added here to help with pickling a SeqRecord in the past:
I'm not certain, but the attached diff seems to work.
Strictly speaking ExactPosition, BeforePosition and AfterPosition should also define __getnewargs__ returning the __new__ arguments position and extension. I haven't done so here because:
extension is only available to the instance by way of a method marked obsolete
in practice it doesn't matter because extension is defined by default and any other value raises an error
Activity
peterjc commentedon Aug 12, 2019
Do you know enough about pickle to fix this and add a couple of unit tests, e.g. to
Tests/test_SeqFeature.pyfor the positions, and perhaps also higher level inTests/test_SeqRecord.py?You can see a test added here to help with pickling a
SeqRecordin the past:https://github.com/biopython/biopython/blob/biopython-174/Bio/SeqRecord.py#L50
macraild commentedon Aug 13, 2019
I'm not certain, but the attached diff seems to work.
Strictly speaking ExactPosition, BeforePosition and AfterPosition should also define __getnewargs__ returning the __new__ arguments position and extension. I haven't done so here because:
2207diff.txt
peterjc commentedon Aug 13, 2019
Other than a repeated typo ("intances"), that looks good. Could you submit it as a pull request please?