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

前端 未结 3 2099
北海茫月
北海茫月 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:24

    I don't think it is possible to persuade Sphinx to be more "friendly" as long as you have a sentinel that creates an object outside the function. Sphinx' autodoc extension imports the module, which means that module-level code is executed.

    Are you sure you can't use something like this?

    def foo(param1=None):
        if param1 == None:
            param1 = whatever you want...
        else:
             ... 
    

提交回复
热议问题