【问题标题】:How to make VS code IntelliSense to show class only attributes not the built object attributes?如何使 VS 代码 IntelliSense 仅显示类属性而不显示构建对象属性?
【发布时间】:2020-12-07 16:13:48
【问题描述】:

我有一个 python 类,我只想查看智能感知建议中的类属性。

class car():
    def __init__(self, brand, model, year):
        self.brand = brand
        self.model = model
        self.year = year


c1 = car()

当我使用“c1”时。我看到“__ dir__”、“__ getattribute__”等结果。但我只想在智能感知建议中看到“品牌”、“型号”和“年份”。

有什么可以覆盖这种行为吗?

【问题讨论】:

    标签: python visual-studio-code intellisense


    【解决方案1】:

    之所以显示“__ dir__”,“__ getattribute__”是代码中使用的“__init__”方法,来源于文件“builtins.pyi”,而这个文件中还包含“__ dir__”, "__getattribute__":

    解决方法:例如关闭“__dir__”:(注释掉“builtins.pyi”中的“def __dir__(self) -> Iterable[str]: ...”)

    之前:

    之后:

    更新:

    我尝试依次关闭其他显示器,以下是我在“builtins.pyi”中注释的代码:

    只剩下四个选项:(因为这个文件定义了它们)

    但是,为了避免影响代码的使用,不建议您更改此文件。而且这不影响提示内容“品牌”、“型号”、“年份”作为第一个显示:(我用小框的时候会显示偏好,并保留。)

    【讨论】:

    • 谢谢@Jill Cheng。在“builtins.pyi”中注释掉“def dir__(self) -> Iterable[str]: ...”仍会显示其他内置方法,如“__dict”、“doc","eq"...在建议中。但我只想在建议中看到“品牌”、“型号”和“年份”。你能告诉我你在上一个视频 sn-p 中做了什么来实现这个目标吗?
    • @Navya Krishna - 当我将提示框的大小调整为小框时,似乎只会显示偏好并保留。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-18
    • 1970-01-01
    • 2016-09-17
    • 1970-01-01
    • 2017-09-13
    • 2019-08-08
    相关资源
    最近更新 更多