0

On some functions with type hint, when many type can be return, and if None is available

(method) get_instance: (config_dict: Unknown) -> Self@DBConnector | None

if it use it

    db_obj = DBConnector.get_instance(configUtil.config)
    connection = db_obj.get_connection()

db_obj.get_connection() is in red, and the message when i mouse over is

Cannot access member "get_connection" for type "None" Member "get_connection" is unknownPylancereportGeneralTypeIssues

I tried to find content on this, but found nothing

jmnguye
  • 347
  • 2
  • 9
  • 2
    I would suggest adding `if db_obj is not None` to your code. The bug is not in the type checker, but in your own code. Pylance is correct – SurDin Dec 21 '21 at 09:34
  • Ok, i did what you say, and it works, i was not aware about this, but now, it seems obvious for me (after you showing me the light), but i have other issue where pylance is complaining. I think it's legit, but somehow i don't understand the issue ```Cannot access member "info" for type "list[str]" Member "info" is unknownPylancereportGeneralTypeIssues info: Unknown | Any``` using ```current_app.logger.info("show me the money") ``` – jmnguye Dec 22 '21 at 17:14
  • looks like your `current_app.logger` is documented as `list[str]` instead of `logging.Log` or something similar – SurDin Dec 23 '21 at 12:33
  • i agree with you, but i applied this : https://stackoverflow.com/questions/16994174/in-flask-how-to-access-app-logger-within-blueprint . From what i've understand, current_app is a proxy to the "main" application which should declare somehow the logger. But in my case, i dont have it declare in the main program, this could be the issue, i'll still digging – jmnguye Dec 27 '21 at 12:32

1 Answers1

0

Found fix on this https://github.com/microsoft/pylance-release/issues/371

this is due on how pylance behave : enter link description here

i've edited my vscode config

"python.analysis.typeCheckingMode": "off"

jmnguye
  • 347
  • 2
  • 9