Snippet from CPy stdlib urlparse.py:
class Quoter(collections.defaultdict):
def __init__(self, safe):
"""safe: bytes object."""
self.safe = _ALWAYS_SAFE.union(safe)
You see, it doesn't call super().__init__(). That's because it relies on __new__ to initialize base class automatically. Specifically for CPy, collections.defaultdict is at all native type, and to emulate its behavior we need __new__.
Another testcase:
class Base:
def __new__(cls):
print("Base __new__")
class Sub(Base):
pass
o = Sub()
Snippet from CPy stdlib urlparse.py:
You see, it doesn't call
super().__init__(). That's because it relies on__new__to initialize base class automatically. Specifically for CPy, collections.defaultdict is at all native type, and to emulate its behavior we need__new__.Another testcase: