[Python-ideas] class-only methods without using metaclasses

Nick Coghlan ncoghlan at gmail.com
Fri Mar 8 12:15:32 CET 2013

On Fri, Mar 8, 2013 at 8:45 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Surely that only applies to the implementation, not the concept itself?
> The interface is trivially easy to explain to anyone even half-way familiar
> with Python's OO model.
> Class methods are accessible from either the class or the instance, and
> receive the class (not the instance) as the first argument.
> Class-only methods are only accessible from the class.

I agree the technical distinction isn't subtle.

> I'm not sure what use class-only methods are or what problems they solve,
> apart from a general dislike of being able to call classmethods from an
> instance. I can't think of any case where I would want to actively prohibit
> calling a classmethod from an instance, so I don't know that this actually
> solves any problems.

It's the "When would I recommend using this over a normal
classmethod?" that I consider subtle. By only providing one of the two
options directly, it means people don't even need to ask the question,
let alone figure out how to answer it.

> But it looks interesting and I think Eric should
> put it up as a recipe on ActiveState.

Yes, it's certainly a reasonable thing to post as a recipe.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list