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
  How does sqlite3 module determine value type mirlos 2 938 Dec-12-2023, 09:37 AM
Last Post: mirlos
  is import cointegration_analysis a recognized module mitcht33 1 432 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 1,435 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 723 Aug-06-2023, 01:09 AM
Last Post: aupres
  import module error tantony 5 3,457 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module one step back of the path prathampatel9 1 1,083 Sep-21-2022, 01:34 PM
Last Post: snippsat
  Can't install nor import delorean module Tek 3 2,814 Oct-27-2021, 03:32 AM
Last Post: Tek
  import module with syntax error Skaperen 7 5,319 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  'urllib3' Module not found when import 'requests' spanz 5 10,280 Jan-06-2021, 05:57 PM
Last Post: snippsat
  Problem with Flask Bcrypt import module marcello86 2 5,737 Aug-31-2020, 08:10 PM
Last Post: marcello86

Forum Jump:

User Panel Messages

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