Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197554
| From | pa@see.signature.invalid (Pierre Asselin) |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | staticmethod(cls) |
| Date | 2025-09-04 19:28 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <109cp9l$f41$1@reader1.panix.com> (permalink) |
For reasons I won't go into I ended up defining classes inside of
a class body. That's not in the manual, but I see no reason it would
fail.
But then, I accidentally decorated the inner classes with
@staticmethod! It didn't break anything, but it had an interesting
side effect: help() and pydoc on the outer class shows the docs
of the inner class members. Normally only the inner classes are
listed, not their contents.
Here's a minimal example.
----------------------------------------------------------------------
class Outer:
'''Outer class'''
def outer_method(self):
'''outer method'''
class Inner0:
'''Inner class'''
def inner_0(instance):
'''inner method, not seen by pydoc.'''
@staticmethod
class Inner1:
'''Inner class passed through staticmethod()'''
def inner_1(instance):
'''inner method, visible to pydoc !'''
----------------------------------------------------------------------
Save and run pydoc, or import and run help(_module_.Outer).
Now that's *seriously* not-in-the-manual. I won't rely on that
behavior, plus the expanded documentation is a bit too much,
but I'm curious as how that interaction between staticmethod()
and help()/pydoc came about.
--
pa at panix dot com
Back to comp.lang.python | Previous | Next — Next in thread | Find similar
staticmethod(cls) pa@see.signature.invalid (Pierre Asselin) - 2025-09-04 19:28 +0000 Re: staticmethod(cls) Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-09-05 00:15 +0000
csiph-web