0

I have the following in my __init__.py to avoid the repeated import of the typing library:

from typing import Dict, List, Tuple

yet, when I use Dict in my package code, it raises a NameError 'Dict' is not defined.

Do I have to include the above import statement explicitly in every class?

Note that typing is not my own module, so it is not inside the package directory

martineau
  • 119,623
  • 25
  • 170
  • 301
Uliw
  • 71
  • 5

1 Answers1

0

The import statement has to go at the top (not always) of the code you are programming every time.

__init__.py

from typing import Dict, List, Tuple
    ^ this will not affect main.py 
Dict(blah)
...

Main.py

from typing import Dict, List, Tuple
Dict(jjjj)
martineau
  • 119,623
  • 25
  • 170
  • 301
dontbanmeplz
  • 41
  • 1
  • 5