It would be nice if pydev could provide content assists for objects instantiated using alternate constructors. Currently pydev only provides content assists for objects instantiated using the default constructor for the class, eg:
mydict = dict()
and not for alternate constructors, such as:
mydict = dict.fromkeys([1, 2])
(to try it: type "mydict." and hit Ctrl-Space).
Alternate constructors are commonly implemented in python using @classmethods that return an instance of the class (see toy example in first comment below).
I dont know how hard this would be to implement, but my gut feeling is that most cases could be caught by just looking for @classmethods and see if they return cls(...), which shouldn't be very hard.
I work in bioinformatics and parse a lot of textual data, so most of the objects I work with are instantiated using alternate constructors such as in the toy example and this would be a huge help for me.
Also, thanks for Pydev! It continues to rock my world.
/Joel
Logged In: YES
user_id=1008220
Originator: YES
And the example...
# Toy example:
class Fasta(object):
def __init__(self, sequence=None, id=None, description=None):
self.sequence = sequence
self.id = id
self.description = description
@classmethod
def from_fulltext(cls, text):
lines = text.splitlines()
header = lines.pop(0)
id, description = header[1:].split(None, 1)
sequence = ''.join(lines)
return cls(sequence, id, description)
def fulltext(self):
return '>%s %s\n%s' % (self.id, self.description, self.sequence)
# Example use:
s = """>Moo Cow gene
TACTGACTCAGAGCTGATCGATCTATCGATCGCTAGC
ACTCAGTCAGTACGCTAC
"""
o = Fasta.from_fulltext(s)
print o.fulltext()