AutoComplete / Type hints for global variables

Answered

Hello,

I am using a separate module for global variables. Class variables will be set at run time, so are initiated as None. So autocomplete is note aware of the class type (which is fine). So I am trying to use type hints on those class variable, but Pycharm is not pulling them at all. I tried to use a stub file as well, with no success. Other doc strings are working fine. Any hints?

Example:

**********************

main.py

Import Globals

class cMyclass():

   ### Some Implementation

Globals.oMyClass = cMyClass()

********************

Globals.py

oMyClass = None  # type: cMyClass

*****************

AnyOtherModule.py

Import Globals

Globals.oMyClass.    # No Autocomplete

 

Greetings

Carsten

2 comments

Hi Carsten! To make it work cMyClass should be presented in the global scope of Globals.py. Not sure how to correctly annotate it in your simplified example - architecture seems to be very complicated. As a possible workaround, you can add Globals.pyi and define type there:

from main import cMyClass

oMyClass: cMyClass

Has it helped?

0

Hallo,  

 

works like a (py)charme. Thanks a lot

0

Please sign in to leave a comment.