Прескочи на главни садржај
🔒 Режим прегледа. Првих петнаест Foundations лекција је бесплатно; ова је Pro. Покрените 7-дневни trial да откључате едитор, AI савете и остатак курса. Картица је обавезна, можете отказати у било ком тренутку у Dashboard.Покрени 7-дневни trial →
← KurseviSenior Deep-DivesМодул 1 · Конкуренција и асинхронизовани интерни елементиМетацлассpredict5 / 161
+100 XP
Zadatak🌐 shown in EN
📝 **Task:** Predict the exact output. \`Meta.__new__\` prints \`meta_new:<name>\` as each class is built. \`Base.__init_subclass__\` prints \`init_sub:<name>\` and appends to \`registry\`. Two questions: (1) Does \`init_sub\` fire when \`Base\` itself is created? (2) Inside \`Meta.__new__\` — does \`print\` run before or after \`super().__new__\` builds the class? 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predvidi izlaz

Pažljivo pročitaj kod

class Meta(type):
    def __new__(mcs, name, bases, ns):
        print(f"meta_new:{name}")
        return super().__new__(mcs, name, bases, ns)


class Base(metaclass=Meta):
    registry = []
    def __init_subclass__(cls, **kwargs):
        print(f"init_sub:{cls.__name__}")
        Base.registry.append(cls.__name__)


class A(Base):
    pass


class B(Base):
    pass


print(Base.registry)

Šta će program ispisati? Napiši ovde: