3

Please have a check on the screenshot, enter image description here

In that here self.image has got the pygame.image.load() method on it. but if i have to access all the available methods to self.image object, Pycharm autosuggestions does not list those.

Actually, self.image has got the get_rect to display the rectangle property of the image.

self.rect = self.image.get_rect()

import pygame


class Ship:
    def __init__(self, screen):
        self.screen = screen
        self.image = pygame.image.load('images/ship.bmp')
        self.rect = self.image.
  • Python is a dynamically typed language, which means that the object type is known at execution time and not before. Therefore the auto-complete function may not work fine. Some proposals are made by analyzing your code statically. – tangoal Aug 05 '18 at 19:08
  • @tangoal In that case, referring to the documentation is the only solution to use the methods effectively. for example: [https://www.pygame.org/docs/ref/image.html#pygame.image.load] ** how to understand what are the objects returned to this variable in runtime, in my case, pygame.image.load has been invoked, documentation does not list all the methods that could be used. ** – Rocking Raphsody Aug 05 '18 at 19:13
  • You also just can open the external module in your IDE to view all method names. – tangoal Aug 05 '18 at 20:22
  • @tangoal thats a cool idea. so here self.image is an object of surface class and when i click the getrect() method, surface.py opens and the method is an empty one just got the pass declared under it. `self.image = pygame.image.load('images/ship.bmp') self.rect = self.image.get_rect()` – Rocking Raphsody Aug 06 '18 at 17:10

1 Answers1

4

If Pycharm isn't giving you good suggestions, that's because it can't figure out what you're looking at. Python is duck typed. What a function takes or returns could be any type. But maybe you already know what it is. Pycharm's suggestions get better if you add type annotations for your functions or variables. Use Alt+Enter when your cursor is on a function or variable declaration to add type hints.

You can also use F1 to get help for the item under the cursor and you can Ctrl+click on a variable to jump to where it was defined.

gilch
  • 10,813
  • 1
  • 23
  • 28