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
Please sign in to leave a comment.
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:
Has it helped?
Hallo,
works like a (py)charme. Thanks a lot