Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Python 3.13.0a3 metaclass __call__ runs only once  #114806

Closed
@sklam

Description

@sklam

Bug report

Bug description:

Metaclass __call__ is expected to run everytime a class is instantiated but in Python 3.13 it only run once.

Minimal reproducer:

class _TypeMetaclass(type):
    def __call__(cls, *args, **kwargs):
        print("Metaclass.__call__", cls.__qualname__, args)
        inst = type.__call__(cls, *args, **kwargs)
        return inst


class Type(metaclass=_TypeMetaclass):
    def __init__(self, obj):
        self._obj = obj


class Function(Type):
    pass

for i in range(100):
    Function(i)

On python 3.12, the output is:

Metaclass.__call__ Function (0,)
Metaclass.__call__ Function (1,)
Metaclass.__call__ Function (2,)
...
Metaclass.__call__ Function (98,)
Metaclass.__call__ Function (99,)

On python 3.13 (docker image 3.13.0a3-bullseye), the output is unexpectedly:

Metaclass.__call__ Function (0,)

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)release-blockertype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions