Decorated class question

D

deathweaselx86

Pardon me if this is a silly question.

If I decorate a class, then subclass it, does my subclass feature
whatever the decorator did to my superclass?

Thanks in advance.
 
D

Devin Jeanpierre

If I decorate a class, then subclass it, does my subclass feature
whatever the decorator did to my superclass?

Yes. The following two things are completely equivalent:

@foo
class Bar(...):
...

# and

class Bar(...)
...
# immediately afterward
Bar = foo(Bar)

-- Devin
 
I

Ian Kelly

Pardon me if this is a silly question.

If I decorate a class, then subclass it, does my subclass feature
whatever the decorator did to my superclass?

That depends on what the decorator did. Changes made directly to the
class itself, such as items added to the class dict, will be
inherited. Other operations performed, such as registering the class
with a framework of some sort, are not inherited and would need the
decorator to be applied to the subclass as well.

Cheers,
Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,151
Messages
2,570,854
Members
47,395
Latest member
GennieGinn

Latest Threads

Top