'Why can't VSCode provide code completions for my object?

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()


Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SuperStormer