Prejsť na hlavný obsah
🔒 Režim náhľadu. Prvých pätnásť lekcií Foundations je zadarmo; táto je Pro. Spustite 7-dňový trial pre odomknutie editora, AI nápovied a zvyšku kurzu. Karta vyžadovaná, zrušte kedykoľvek v Dashboard.Spustiť 7-dňový trial →
← KurzySenior Deep-DivesModul 1 · Concurrency & Async InternalsMetatriedypredict5 / 161
+100 XP
Úloha🌐 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.
Predpovedz výstup

Prečítaj kód pozorne

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)

Čo program vypíše? Napíš sem: