Python Forum
Import a module for use in type hint?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Import a module for use in type hint?
#1
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
        """
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question how to type hint a function in a dataclass? Calab 3 829 Feb-27-2025, 04:40 AM
Last Post: Calab
  How can I create this type hint. deanhystad 0 594 Aug-05-2024, 07:55 PM
Last Post: deanhystad
  How does sqlite3 module determine value type mirlos 2 2,196 Dec-12-2023, 09:37 AM
Last Post: mirlos
  is import cointegration_analysis a recognized module mitcht33 1 1,138 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 10,251 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 1,377 Aug-06-2023, 01:09 AM
Last Post: aupres
  import module error tantony 5 4,984 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module one step back of the path prathampatel9 1 1,817 Sep-21-2022, 01:34 PM
Last Post: snippsat
  Can't install nor import delorean module Tek 3 4,207 Oct-27-2021, 03:32 AM
Last Post: Tek
  import module with syntax error Skaperen 7 8,622 Jun-22-2021, 10:38 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020