0

It seems unnecessary to me.

But I still wondering why some sample codes (python3) still inherit this style.

For example (quoted from Django 2 by Example):

from django.contrib.auth.models import User

class EmailAuthBackend(object):
    ....


Can someone explain a bit?

Thanks!

khelwood
  • 55,782
  • 14
  • 81
  • 108
xemexpress
  • 177
  • 1
  • 13

2 Answers2

2

It's not necessary. In Python 2 you had to do this to opt in to new-style classes; in Python 3, all classes are automatically "new-style" (old-style doesn't exist), so inheriting from object is equivalent to not inheriting from anything.

Likely the code you're seeing is legacy code that was directly adapted from older Python 2 code, or written by someone with Python 2 habits, and they never bothered to remove the explicit object base, since it's harmless to leave it in.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
1

No, now this is no longer necessary. I think this code was left for backward compatibility.

SimfikDuke
  • 943
  • 6
  • 21