在哪里可以找到函数的kwargs/args的文档 [英] Where to find documentation of kwargs/args of functions

查看:61
本文介绍了在哪里可以找到函数的kwargs/args的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数库(例如请求或matplotlib)都不包含有关kwargs/args的适当文档.有时有一些示例,但大多数情况下缺少特定的用例.

Most of the libraries like requests or matplotlib don't include proper documentation of kwargs/args. There are sometimes examples but mostly the specific use case is missing.

我的问题:

  1. 我在哪里可以找到该分类信息.
  2. 为什么开发人员无法正确记录kwargs/args

推荐答案

我只是试图在许多类似的实例中找到源.通常,如果没有记录,则将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. Once you know what low-level function the higher-level function is deferring to, the purpose will make more sense.

例如,看看 requests的文档.request .如您所述,它表明该方法采用 kwargs ,但未提及其用法.确实,但是为我们提供了方便的链接到源,它显示:

For example, take a look at the docs for requests.request. As you mention, it shows that that method takes a kwargs, but doesn't mention its use. 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)

因此,我们可以看到,它是对 sessions 的实例方法 request 的相当薄的包装,它只是向下传递了 kwargs .

So, we can see that it's a fairly thin wrapper over sessions' instance method request, where it just passes the kwargs down.

如果我们检查该方法的源怎么办?:

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):
    . . .

我们可以看到 kwargs 得到了扩展,并且有望成为这些参数之一.此时,我们可以查看该方法的文档可以更好地了解每个参数的作用.

We can see that the kwargs get expanded, and would be expected to be one of these parameters. At that point, we can check the documentation for that method to get a better idea about what each parameter does.

我会注意到,如果您使用的是Pycharm,则可以在符号上方的 ctrl + b 跳转到其源代码,因此不要甚至需要跟踪源进行任何侦查.

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.

为什么不记录它们?人们在写作时会很懒惰和/或错过重要的细节.他们可能已经预料到它足够直观".不需要记录每个细节.谁知道.有时,您会比从文档中了解到更多有关源代码的知识.

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.

这篇关于在哪里可以找到函数的kwargs/args的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆