Seems to me that you should be doing:
import re
print(re.sub('class', 'function', 'Class object', flags=re.I))
Without this, the re.I argument is passed to the count argument.
Seems to me that you should be doing:
import re
print(re.sub('class', 'function', 'Class object', flags=re.I))
Without this, the re.I argument is passed to the count argument.