Documenting with Sphinx python methods that do have default parameters with sentinel objects?

前端 未结 3 2089
北海茫月
北海茫月 2021-01-20 21:48

If you want to be able to allow people to call some methods using None you have to do use a sentinel object when you define the method.

 _senti         


        
3条回答
  •  执笔经年
    2021-01-20 22:35

    The part of generated method signature can be changed by overriding the __repr__ method of the sentinel object.

    _sentinel = type('_sentinel', (object,),
                     {'__repr__': lambda self: '_sentinel'})()
    

    It will be rendered by Sphinx as something like this:

    mymodule.foo(param1=_sentinel)
    

    提交回复
    热议问题