Why is python BaseHTTPServer an old-style class?

Is there any reason python BaseHTTPServer.HTTPServeris an old-style class?

>>> import BaseHTTPServer
>>> type(BaseHTTPServer.HTTPServer)
classobj

I ask because I want to use superin a class that inherits from HTTPServerand cannot. There is a workaround:

class MyHTTPServer(HTTPServer,object):
    ...

Does this workaround have any hidden gotchas?

+3
source share
1 answer

According to Steve Holden ,

... it was easier to leave them as they were than risk
introducing incompatibilities.

The problem was fixed in Python3, where all classes are new-style classes.


Currently, we only see the benefits of the new style classes, and we are used to programming in ways that are compatible with the new style. However, when classic classes were the norm, there might be code like this:

def __str__():
    return "I'm Classic"

class Classic: pass

c = Classic()
c.__str__ = __str__
print(c)

I'm Classic

, , :

class New(object): pass
n = New()
n.__str__ = __str__
print(n)

<__main__.New object at 0xb746ad4c>

, __str__ , ( MRO) , . .

Python2 , Python2 lib .

+4

All Articles