我正在尝试为课堂实例自动完成方法参数名称,但无法弄清楚。举此示例类:
class Abc:
def meth(param):
pass
如果我键入 abc.meth(p
,请按 tab 我看到 param =
的预期完成:

但是,如果我尝试使用类的实例 abc()。甲基结果:
我在Jupyterlab和VS代码中都看到了相同的行为,以及这对于Scikit Learn等其他软件包的实例有效的事实,我认为我缺少某些东西。
<
如何获得与 abc()
类的实例相似的类似于 LinearRegression
类的实例?
I am trying to get auto completion of method parameter names for class instances but can't quite figure it out. Take this example class:
class Abc:
def meth(param):
pass
If I type Abc.meth(p
and press Tab I see the expected completion of param=
:

However, if I try to do the same with an instance of the class Abc().meth(p
, I don't see param
in the completion results:

I see the same behavior in both JupyterLab and VS Code, and the fact that this works for instances of other packages such as scikit learn, I think there is something I am missing.

How can I get method parameter completion for an instance of my Abc()
class similar to the LinearRegression
class above?
发布评论
评论(1)
基于Jupyterlab版本3.2.9上的实验,这似乎是因为自动完成试图考虑
self
和cls
之类的隐式参数。包括self
参数应主要解决您的问题。这些是我为上述类提出的完成选项:
标准行为很好,但是
abc()的结果是两个装饰器的错误
都是错误的。如staticmethod
) andclassMethod
因此使用装饰器时,这两个列都应该是相同的,但是它总是从中省略一个参数
abc()。Meth
,大概是self
。即使cls
正确处理abc.meth
在使用@ClassMethod
时,它最终在abc()中省略了两个参数。 .METH
而是。Visual Studio代码1.67.1的测试给出了所有情况的正确自动完成选项。因此,由于
param
取而代之的是self
,并且没有其他参数。Based on experimentation on JupyterLab Version 3.2.9, this seems to be because the autocomplete tries to account for implicit parameters like
self
andcls
. Including aself
parameter should mostly fix your issues.These are the completion options I was presented for the class above:
The standard behavior is fine, but the results for
Abc().meth
are wrong with both decorators. As mentioned in the docs forstaticmethod
andclassmethod
:So both columns should have been the same when decorators are used, but it always omits one parameter from
Abc().meth
, presumably forself
. And even thoughcls
is correctly handled forAbc.meth
when using@classmethod
, it ends up omitting two parameters inAbc().meth
instead.Testing with Visual Studio Code 1.67.1 gave the correct autocomplete options for all cases. So the missing suggestion you experienced there is expected behavior since
param
takes the place ofself
and there are no other parameters.