Python Forum

Full Version: Import a module for use in type hint?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!
I have my own class called ShareData which consist all game settings, images, sounds etc. I pass one instance of ShareData as an __init__ argument(argument name is 'data') to the all other objects in project(game states, game objects etc.) in a few different modules. I use type hints and there i have a question.
How should I type hint 'data' argument if ShareData is in in other module? Should I import ShareData class from another module into all other modules which use it just for writing a type hint? Isn't it form over substance? Example of one class which use argument data:

class Projectile(pygame.sprite.Sprite):
    """Projectile object"""
    def __init__(self, data: ???, pos_x: int, pos_y: int, style: str) -> None:  # Should I import 'from ..control import ShareData' and write 'data: ShareData'?
        """
        Parameters:
            pos_x: x position where projectile will apear
            pos_y: y position where projectile will apear
            style: projectile type
        """