Home > Net >  How to find all undefined and unresolved references in a Python project
How to find all undefined and unresolved references in a Python project

Time:10-25

I'm working on a Python project on VScode and facing some debugging issues:

  1. The built-in debugger does not detect errors inside functions. For example, it doesn't care the following invocation of an undefined method inside the function unless function1 is called in the main thread. Because mine is a Flask project, there are a large number of functions that are not called on running the code.

    def function1():
        undefined_method()
    
    
  2. Although the "Problems" panel at the bottom detects this kind of issue, it detects only opened files, not all in the project.

  3. Besides, the "Problems" panel doesn't consider the following unresolved reference:

    import requests
    requests.unknown_object
    # You know that 'requests' has no attribute such as 'unresolved_object'
    # But this issue is not listed on "Problems".
    

Is there any good extension to properly inspect the whole project?

CodePudding user response:

Enable linting

enter image description here

enter image description here

enter image description here

Or add the following configuration in the settings.json

    "python.analysis.typeCheckingMode": "strict",
  • Related