Yohan Chevalier
Yohan Chevalier

Reputation: 73

Visual Code IntelliSense doesn't recognize object's attributes

As an example, in this sample, the last attribute (dict_criteria) cannot be identified by Visual Code. Auto_completion doesn't work. BUT the code works pretty well.

1 import judilibre_connexion as j_co
2 import judilibre_url as j_url
3   
4 co = j_co.ConnexionJudi()
5 rec3 = j_url.SearchURL("licenciement")
6 co.send_request(rec3)
7 print(co.dict_answers[2].dict_criteria)

I create an object from ConnexionJudi class. Using the method send_request in line 6 adds in the instance attribute named dict_answer an object from another class (j_ans) and another module which I didn't import in this file. If I import it, the linter says that the import is useless.

current file -> co object -> co instance attribute (dict) -> value from key [2] (object from another class) -> attribute of this object.

Screenshot from the tool, the attribute is white instead of blue (it hasn't been identified by vs code):

enter image description here

Upvotes: 2

Views: 950

Answers (1)

Niemand
Niemand

Reputation: 23

In order for Intellisense to know the attributes of a dictionary (or a list), you need to hint the type. E.g. my_dict: [str, list] = {}. Pay attention to the "append" method here: enter image description here

Upvotes: 1

Related Questions