python - How to extend a static base constructor? -
i'm using python bitmap package.
it need, don't work hexadecimal values, needed application, extended this:
import bitmap class bitmap(bitmap.bitmap): def tohexstring(self): val = self.tostring() st = "{0:0x}".format(int(val,2)) return st.zfill(self.sz/4) the base class has static constructor string:
bitmap.bitmap.fromstring("01010101") i can make 1 hexadecimal converting hex value bin:
bitmap.bitmap.fromstring(format(int("aa",16),"08b")) but returned class original bitmap class , not extended one.
how can use constructor still return extended class?
bitmap.bitmap.fromstring class method, not static method, has been implemented incorrectly author. line:
bm = bitmap(nbits) should be
bm = cls(nbits) in case call fromstring on subclass , an instance of subclass. fork repo, implement , make pull request have included in package (or use fork in package). raise issue on repo see how they'd prefer proceed.
alternatively, implement fromstring correctly in own subclass , shadow broken base class implementation.
Comments
Post a Comment