'pycharm code completion for objects retrieved from constructed dictionary
I have number of similar objects, and want to use dict as mapping to get the desired one, i.e.
from typing import NamedTuple
NT= NamedTuple("test", param_a=int) # more complex
nt1 = NT(param_a=1)
nt2 = NT(param_a=2)
my_dict={1:nt1, 2:nt2} #based on key, my_dict will 'return' desired namedtuple
manually stating all key value pairs like above would allow code completion when using my_dict with parameter to represent the key
key = 1 # just to illustrate,actually will be computed or provided by user
my_dict[key]. # code completion does work here, after pressing dot '.' I'm offered param_a
However if the dict is constructed via comprehension code completion does not work
my_dict = { x.param_a:x for x in [nt1,nt2] } # key construction will be complex, also I may have numerous namedtuples, hence using dict comprehension to build my_dict
key= 1
my_dict[key]. # code completion does NOT work anymore
How can I achieve code completion for constructed dict? I realize primitive hack could be just temporarily include my_dict={1:nt} just to allow writing further code with code completion enabled, however I'd have to add this (and remember to remove!) everytime I'd like to make change with code completion
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
