diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c2cd74f73542..174a616e54a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,6 +70,31 @@ jobs: with: node_version: ${{ env.NODE_VERSION }} + check-types: + name: Check Python types + if: github.repository == 'microsoft/vscode-python' + runs-on: ubuntu-latest + steps: + - name: Use Python ${{ env.PYTHON_VERSION }} + uses: actions/setup-python@v2 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Checkout + uses: actions/checkout@v2.3.4 + + - name: Install Python requirements + run: | + python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy + python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt --no-user + python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/jedilsp --no-cache-dir --implementation py --no-deps --upgrade -r ./pythonFiles/jedilsp_requirements/requirements.txt + python -m pip install --upgrade -r build/test-requirements.txt + + - name: Run Pyright + uses: jakebailey/pyright-action@v1 + with: + working-directory: 'pythonFiles' + ### Non-smoke tests tests: name: Tests diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index eb94112cb278..5f7bfaaaab02 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -46,6 +46,30 @@ jobs: with: node_version: ${{ env.NODE_VERSION }} + check-types: + name: Check Python types + runs-on: ubuntu-latest + steps: + - name: Use Python ${{ env.PYTHON_VERSION }} + uses: actions/setup-python@v2 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Checkout + uses: actions/checkout@v2.3.4 + + - name: Install Python requirements + run: | + python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy + python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt --no-user + python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/jedilsp --no-cache-dir --implementation py --no-deps --upgrade -r ./pythonFiles/jedilsp_requirements/requirements.txt + python -m pip install --upgrade -r build/test-requirements.txt + + - name: Run Pyright + uses: jakebailey/pyright-action@v1 + with: + working-directory: 'pythonFiles' + ### Non-smoke tests tests: name: Tests diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index 772de0f9648d..e68231059748 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -55,7 +55,8 @@ def _get_statements(selection): # In Python 2.7, lineno takes into account decorators, so this offset check is unnecessary. # Also, not all AST objects can have decorators. if hasattr(node, "decorator_list") and sys.version_info.major >= 3: - line_end -= len(node.decorator_list) + # Using getattr instead of node.decorator_list or pyright will complain about an unknown member. + line_end -= len(getattr(node, "decorator_list")) ends.append(line_end) ends.append(len(lines)) @@ -71,7 +72,8 @@ def _get_statements(selection): # Special handling of decorators similar to what's above. if hasattr(node, "decorator_list") and sys.version_info.major >= 3: - start -= len(node.decorator_list) + # Using getattr instead of node.decorator_list or pyright will complain about an unknown member. + start -= len(getattr(node, "decorator_list")) block = "\n".join(lines[start:end]) # If the block is multiline, add an extra newline character at its end. diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index 52c7c96d11e7..449860745c58 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -9,3 +9,27 @@ exclude = ''' )/ ) ''' + +[tool.pyright] +exclude = ['lib'] +extraPaths = ['lib/python', 'lib/jedilsp'] +ignore = [ + # Ignore all pre-existing code with issues + 'get-pip.py', + 'install_debugpy.py', + 'tensorboard_launcher.py', + 'testlauncher.py', + 'visualstudio_py_testlauncher.py', + 'testing_tools/unittest_discovery.py', + 'testing_tools/adapter/util.py', + 'testing_tools/adapter/pytest/_discovery.py', + 'testing_tools/adapter/pytest/_pytest_item.py', + 'tests/debug_adapter/test_install_debugpy.py', + 'tests/testing_tools/adapter/.data', + 'tests/testing_tools/adapter/test___main__.py', + 'tests/testing_tools/adapter/test_discovery.py', + 'tests/testing_tools/adapter/test_functional.py', + 'tests/testing_tools/adapter/test_util.py', + 'tests/testing_tools/adapter/pytest/test_cli.py', + 'tests/testing_tools/adapter/pytest/test_discovery.py', +]