You don't need to return the object, the object you pass in the argument to the function will have the attrib set and you can refer it directly from the caller code.
class A:
def __init__(self, attrib):
self.attrib = attrib
def function(obj):
obj.attrib = 8
obj = A(5)
#This line prints 5
print(obj.attrib)
#5
function(obj)
#This line prints 8
print(obj.attrib)
#8
Or a better approach might be:
class A:
def __init__(self, attrib):
self.attrib = attrib
def function(self, attrib):
self.attrib = attrib
obj = A(5)
print(obj.attrib)
#5
obj.function(8)
print(obj.attrib)
#8
;soobj.attrib = 8; return objshould do that. But I guess, you are looking for a trick. I don't think there is one.