Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.13.0a3 metaclass __call__ runs only once #114806

Closed
sklam opened this issue Jan 31, 2024 · 2 comments
Closed

Python 3.13.0a3 metaclass __call__ runs only once #114806

sklam opened this issue Jan 31, 2024 · 2 comments
Assignees
Labels
3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error

Comments

@sklam
Copy link

sklam commented Jan 31, 2024

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

@sklam sklam added the type-bug An unexpected behavior, bug, or error label Jan 31, 2024
@ronaldoussoren ronaldoussoren added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 31, 2024
@Eclips4 Eclips4 added the 3.13 bugs and security fixes label Jan 31, 2024
@Eclips4
Copy link
Member

Eclips4 commented Jan 31, 2024

Bisected to 04492cb
cc @markshannon

@Eclips4
Copy link
Member

Eclips4 commented Jan 31, 2024

Thanks Alex for adding release-blocker label. This is definitely should be fixed until the next release of 3.13.
This change can affect a lot of python code. For example - ORM like SQLAlchemy which uses a lot of metaclasses (thanks @wrongnull for pointing this out!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error
Projects
Development

No branches or pull requests

5 participants