• staticmethod(cls)

    From pa@[email protected] (Pierre Asselin) to comp.lang.python on Thu Sep 4 19:28:53 2025
    From Newsgroup: comp.lang.python

    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
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@[email protected] to comp.lang.python on Fri Sep 5 00:15:10 2025
    From Newsgroup: comp.lang.python

    On Thu, 4 Sep 2025 19:28:53 -0000 (UTC), Pierre Asselin wrote:

    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.

    Note that the help for Inner1 is listed in the section of the help for
    Outer headed “Static methods defined here:”. So all that’s happening is that the help() function is looking for class members that have been put through staticmethod(), whatever their type is, and I think recursively putting them through their own help() calls.
    --- Synchronet 3.21a-Linux NewsLink 1.2