[英]How to make VS code IntelliSense to show class only attributes not the built object attributes?
我有一个 python class 并且我只想查看智能感知建议中的 class 属性。
class car():
def __init__(self, brand, model, year):
self.brand = brand
self.model = model
self.year = year
c1 = car()
当我使用“c1”时。 我看到的结果如“__ dir__”、“__ getattribute__”等。但我只想在智能感知建议中看到“品牌”、“型号”和“年份”。
有什么可以覆盖这种行为吗?
之所以显示“__dir__”、“__getattribute__”,是因为代码中使用的“ __init__
”方法,来源于文件“builtins.pyi”,而这个文件中还包含“ builtins.pyi
__”、“__getattribute__”:
解决方法:例如关闭“ __dir__
”:(在“builtins.pyi”中注释掉“def builtins.pyi
def __dir__(self) -> Iterable[str]: ...
”)
前:
后:
更新:
我尝试依次关闭其他显示器,以下是我在“ builtins.pyi
”中注释的代码:
只剩下四个选项:(因为这个文件定义了它们)
但是,为了避免影响代码的使用,不建议您更改此文件。 而且这不影响提示内容“品牌”、“型号”、“年份”作为第一个显示:(我用小框的时候会显示偏好,保留。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.