Skip to content

Need to implement proper __new__ handling for instance classes #606

@pfalcon

Description

@pfalcon

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    py-coreRelates to py/ directory in source

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions