Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Documentation (:obj:`str`) vs (str)

Tags:

python

string

I have been reading the this Example Google Style Python Docstrings document to understand how good Python documentation is written. But I can't understand one thing.

When documenting strings, there is this weird notation.

For example when documenting arguments, the documentation specifies they be written like :

Args: 
    arg1(str): The description for arg1

But, in some other places, the document writes something like :

Args: 
    param2 (:obj:`str`, optional): The second parameter.

In the second case, why is the string represented as :obj:`str` and not just plain str? Why two representations for strings in the first place? When do I use which?

like image 826
ironstein Avatar asked Aug 16 '16 07:08

ironstein


1 Answers

I think that the answer to your question is given in Python: Journey from Novice to Expert. Apparently, if you write :obj:str, your Sphinx documentation will contain a link to the str object in the standard Python documentation.

By the way, this notation is not restricted to strings. In the docstrings of the ExampleError class in Example Google Style Python Docstrings it says:

Args:
    msg (str): Human readable string describing the exception.
    code (:obj:`int`, optional): Error code.
like image 81
user1919235 Avatar answered Oct 31 '22 21:10

user1919235