简体   繁体   English

在哪里可以找到函数的 kwargs/args 文档

[英]Where to find documentation of kwargs/args of functions

Most of the libraries like requests or matplotlib don't include proper documentation of kwargs/args.大多数库,如 requests 或 matplotlib 不包含 kwargs/args 的正确文档。 There are sometimes examples but mostly the specific use case is missing.有时会有示例,但大多数情况下都缺少特定的用例。

My Questions:我的问题:

  1. Where can I find that sorta information.我在哪里可以找到那种分类信息。
  2. Why developers don't document the kwargs/args properly为什么开发人员没有正确记录 kwargs/args

I just try to find the source in many instances like that.我只是试图在很多这样的情况下找到源头。 Usually, if it's not documented, the args are being passed to some lower level function.通常,如果没有记录,args 将被传递到某个较低级别的 function。 Once you know what low-level function the higher-level function is deferring to, the purpose will make more sense.一旦你知道低级 function 和高级 function 遵循什么,目的就会更有意义。

For example, take a look at the docs forrequests.request .例如,查看requests.request的文档。 As you mention, it shows that that method takes a kwargs , but doesn't mention its use.正如您所提到的,它表明该方法需要一个kwargs ,但没有提到它的用途。 It does however give us a handy link to the source , which shows:但是,它确实为我们提供了指向源的便捷链接,其中显示:

def request(method, url, **kwargs):
    . . .
    with sessions.Session() as session:
        return session.request(method=method, url=url, **kwargs)

So, we can see that it's a fairly thin wrapper over sessions ' instance method request , where it just passes the kwargs down.因此,我们可以看到它是sessions的实例方法request的一个相当薄的包装器,它只是将kwargs向下传递。

What if we check the source for that method?如果我们检查该方法的来源怎么办? :

def request(self, method, url,
            params=None, data=None, headers=None, cookies=None, files=None,
            auth=None, timeout=None, allow_redirects=True, proxies=None,
            hooks=None, stream=None, verify=None, cert=None, json=None):
    . . .

We can see that the kwargs get expanded, and would be expected to be one of these parameters.我们可以看到kwargs得到扩展,并且有望成为这些参数之一。 At that point, we can check the documentation for that method to get a better idea about what each parameter does.此时,我们可以查看该方法的文档,以更好地了解每个参数的作用。

I'll note that if you're using Pycharm, you can ctrl + b over top of a symbol to jump to its source, so you don't even need to track down the source to do any sleuthing.我会注意到,如果您使用的是 Pycharm,您可以ctrl + b在符号顶部跳转到其源,因此您甚至不需要追踪源来进行任何侦查。


Why not document them?为什么不记录它们? People are lazy and/or miss important details when writing things.人们在写东西时很懒惰和/或错过了重要的细节。 They may have expected that it's "intuitive enough" that documenting every detail is unnecessary.他们可能已经预料到不需要记录每个细节是“足够直观的”。 Who knows.谁知道。 Sometimes, you learn more reading the source than you do the documentation for certain details.有时,对于某些细节,您阅读源代码比阅读文档了解更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM