为什么可以为我的对象提供代码完成代码完成?

发布于 2025-01-28 22:59:13 字数 390 浏览 2 评论 0原文

VS代码为什么不弄清楚如何完成方法和属性? 当我写信时: ai_game。 什么都没有发生,没有出现的方法或属性列表

import pygame
 
class Ship:
    """A class to manage the ship."""
    
    def __init__(self, ai_game):
        """Initialize the ship and set its starting position."""
        self.screen = ai_game.screen
        self.settings = ai_game.settings
        self.screen_rect = ai_game.screen.get_rect()

Why doesn't VS Code figure out how to complete the methods and attributes?
When I write:
ai_game.
nothing happens, no list of methods or attributes appear

import pygame
 
class Ship:
    """A class to manage the ship."""
    
    def __init__(self, ai_game):
        """Initialize the ship and set its starting position."""
        self.screen = ai_game.screen
        self.settings = ai_game.settings
        self.screen_rect = ai_game.screen.get_rect()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月流歌 2025-02-04 22:59:13

因为它不知道ai_game是什么。它可以是任何类型。例如,添加类型注释:

def __init__(self, ai_game: float):

在此示例中,我很确定您没有浮点,但是它将帮助代码知道哪种类型是ai_game实际上并为您提供帮助及其方法..

Because it has no idea what ai_game is. It can be any type. Add a type annotation to it for example:

def __init__(self, ai_game: float):

Well in this example I'm pretty sure you don't have a float, but it'll help VS Code to know what type is ai_game actually and help you with its methods..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文