Hello,
      I have a class I wrote for Python2 that needs to be made to work
on Python3. On Python2 it inherited from long, so it needs to inherit
from int on Python3. The following works, but I'm not sure it's the
cleanest solution. It's the first time I've wanted / needed to make a
parent class conditional on the Python version, and I'm not sure it's
even a good idea. I used inheritance because I wanted to perform bitwise
operations on instances, but I could probably switch to composition.
Just wondering how bad the following really is (in a code smell kind of
a away). TIA.

Duncan


import sys

class C_hash(int if sys.version_info.major >= 3 else long):
    def __new__(cls, bits, m, N=1):
        obj = super(C_hash, cls).__new__(cls, bits)
        obj._m = m
        obj._N = N
        return obj
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to