I am converting some python 2.7 code to work with python 3.8. One thing I am stuck on is how to get a reference to im_class working. The original code looks like this:
class UpdateDbQueue():
def __init__(self, **kwargs):
self.job = kwargs["job"]
self.method = self.job
self.cls = self.job.im_class
self.name = "{}.{}".format(self.cls.__name__, self.method.__name__)
Running a debugger shows that kwargs["job"] equals <function DateRange.get_events at 0x112f84f80>
. The python2to3 utility converted the code to this:
class UpdateDbQueue():
def __init__(self, **kwargs):
self.job = kwargs["job"]
self.method = self.job
self.cls = self.job.__self__.__class__
self.name = "{}.{}".format(self.cls.__name__, self.method.__name__)
Which returns an error:
self.cls = self.job.__self__.__class__
AttributeError: 'function' object has no attribute '__self__'
Any idea on how to fix this? I tried changed it simple to self.job.class but got an error KeyError: 'DateRange.get_events'
.
Edit - this is a snipped of the DateRange class.
class DateRange(db.Model): id = db.Column(db.DateTime, primary_key=True)
def get_events(self, rows=10000):
# gets events from database
def __repr__(self):
return "<DateRange (starts: {})>".format(self.id)