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?
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'?
            pos_x: x position where projectile will apear
            pos_y: y position where projectile will apear
            style: projectile type

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't install nor import delorean module Tek 3 601 Oct-27-2021, 03:32 AM
Last Post: Tek
  import module with syntax error Skaperen 7 1,256 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  'urllib3' Module not found when import 'requests' spanz 5 4,068 Jan-06-2021, 05:57 PM
Last Post: snippsat
  Problem with Flask Bcrypt import module marcello86 2 2,093 Aug-31-2020, 08:10 PM
Last Post: marcello86
  Unable to import my own module ThePhantom 3 1,293 May-01-2020, 01:30 AM
Last Post: menator01
  Error while humansize module import. johnkgson 3 1,843 Apr-26-2020, 08:37 AM
Last Post: johnkgson
  from module import function krishanu21 4 1,280 Apr-22-2020, 10:58 AM
Last Post: buran
  Importing module from a package results in import error goghvv 2 1,082 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Import Module and Method ( dynamic ) ? JohnnyCoffee 0 779 Mar-23-2020, 04:23 PM
Last Post: JohnnyCoffee
  how to import a module which is installed to personal folder using pip install --pre? geekgeek 2 1,101 Mar-09-2020, 02:38 PM
Last Post: geekgeek

Forum Jump:

User Panel Messages

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