Search code examples
pythondocstring

Why is the python docstring for `os.CLD_CONTINUED` the same as `int().__doc__`?


I am getting familiar with Python and I thought I would do a dir() walk and examine the doc strings.

I started with the "os" module.

Why is the python docstring for os.CLD_CONTINUED the same as int().__doc__?

I first noticed that CLD_CONTINUED had the same doc string as CLD_DUMPED, CLD_KILLED, etc. Then I realized it's the doc string for int().

I imagine this has something to do with object inheritance.

I checked the Python docs and found https://docs.python.org/3/library/os.html#os.CLD_CONTINUED which says this about CLD__*:

These are the possible values for si_code in the result returned by waitid().

I then went to https://docs.python.org/3/library/os.html#os.waitid which links me to https://docs.python.org/3/library/os.html#os.CLD_EXITED and now I've gone full circle.

Is there someplace else I should look?

I'd like to understand why these si_code docstrings tell me about int().

How can I know when the docstring is not for the thing I'm looking at but for something else? I was really confused at first.


Solution

  • According to [Python.Docs]: Built-in Functions - help() (emphasis is mine):

    If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated.

    os.CLD_CONTINUED (and others as well) is an int value so the help for its class is invoked.

    (py_pc064_03.10_test0) [cfati@cfati-5510-0:/mnt/c/Users/cfati]> python
    Python 3.10.11 (main, Apr  5 2023, 14:15:10) [GCC 9.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    >>> help(123)
    # Help for 'class int(object)' is displayed
    >>> i = 1
    >>> help(i)
    # Same as above
    >>> import os
    >>> os.CLD_CONTINUED, os.CLD_CONTINUED.__class__
    (6, <class 'int'>)
    >>> help(os.CLD_CONTINUED)
    # Same as above
    >>> help(os.CLD_CONTINUED.__class__)
    # Same as above