Python Forum
Import a module for use in type hint? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Import a module for use in type hint? (/thread-35483.html)



Import a module for use in type hint? - Milosz - Nov-08-2021

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