Skip to content

Commit 2883012

Browse files
authored
Run Pyright for all workflows (microsoft#18268)
* Run Pyright for all workflows * Rename job * Remove special directory * analyze types only in pythonFiles * Install requirements * Fix indentation * Indentation, again * Try excluding lib form pyright * install debugger requirements, tweak extraPaths * Remove debugpy install * Exclude more files * Add more to pyproject.toml, install test reqs * Fix normalizeSelection * Move from exclude to ignore * Update build workflow
1 parent 7e1d4ae commit 2883012

4 files changed

Lines changed: 77 additions & 2 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,31 @@ jobs:
7070
with:
7171
node_version: ${{ env.NODE_VERSION }}
7272

73+
check-types:
74+
name: Check Python types
75+
if: github.repository == 'microsoft/vscode-python'
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Use Python ${{ env.PYTHON_VERSION }}
79+
uses: actions/setup-python@v2
80+
with:
81+
python-version: ${{ env.PYTHON_VERSION }}
82+
83+
- name: Checkout
84+
uses: actions/checkout@v2.3.4
85+
86+
- name: Install Python requirements
87+
run: |
88+
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
89+
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
90+
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
91+
python -m pip install --upgrade -r build/test-requirements.txt
92+
93+
- name: Run Pyright
94+
uses: jakebailey/pyright-action@v1
95+
with:
96+
working-directory: 'pythonFiles'
97+
7398
### Non-smoke tests
7499
tests:
75100
name: Tests

‎.github/workflows/pr-check.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ jobs:
4646
with:
4747
node_version: ${{ env.NODE_VERSION }}
4848

49+
check-types:
50+
name: Check Python types
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Use Python ${{ env.PYTHON_VERSION }}
54+
uses: actions/setup-python@v2
55+
with:
56+
python-version: ${{ env.PYTHON_VERSION }}
57+
58+
- name: Checkout
59+
uses: actions/checkout@v2.3.4
60+
61+
- name: Install Python requirements
62+
run: |
63+
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
64+
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
65+
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
66+
python -m pip install --upgrade -r build/test-requirements.txt
67+
68+
- name: Run Pyright
69+
uses: jakebailey/pyright-action@v1
70+
with:
71+
working-directory: 'pythonFiles'
72+
4973
### Non-smoke tests
5074
tests:
5175
name: Tests

‎pythonFiles/normalizeSelection.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def _get_statements(selection):
5555
# In Python 2.7, lineno takes into account decorators, so this offset check is unnecessary.
5656
# Also, not all AST objects can have decorators.
5757
if hasattr(node, "decorator_list") and sys.version_info.major >= 3:
58-
line_end -= len(node.decorator_list)
58+
# Using getattr instead of node.decorator_list or pyright will complain about an unknown member.
59+
line_end -= len(getattr(node, "decorator_list"))
5960
ends.append(line_end)
6061
ends.append(len(lines))
6162

@@ -71,7 +72,8 @@ def _get_statements(selection):
7172

7273
# Special handling of decorators similar to what's above.
7374
if hasattr(node, "decorator_list") and sys.version_info.major >= 3:
74-
start -= len(node.decorator_list)
75+
# Using getattr instead of node.decorator_list or pyright will complain about an unknown member.
76+
start -= len(getattr(node, "decorator_list"))
7577
block = "\n".join(lines[start:end])
7678

7779
# If the block is multiline, add an extra newline character at its end.

‎pythonFiles/pyproject.toml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,27 @@ exclude = '''
99
)/
1010
)
1111
'''
12+
13+
[tool.pyright]
14+
exclude = ['lib']
15+
extraPaths = ['lib/python', 'lib/jedilsp']
16+
ignore = [
17+
# Ignore all pre-existing code with issues
18+
'get-pip.py',
19+
'install_debugpy.py',
20+
'tensorboard_launcher.py',
21+
'testlauncher.py',
22+
'visualstudio_py_testlauncher.py',
23+
'testing_tools/unittest_discovery.py',
24+
'testing_tools/adapter/util.py',
25+
'testing_tools/adapter/pytest/_discovery.py',
26+
'testing_tools/adapter/pytest/_pytest_item.py',
27+
'tests/debug_adapter/test_install_debugpy.py',
28+
'tests/testing_tools/adapter/.data',
29+
'tests/testing_tools/adapter/test___main__.py',
30+
'tests/testing_tools/adapter/test_discovery.py',
31+
'tests/testing_tools/adapter/test_functional.py',
32+
'tests/testing_tools/adapter/test_util.py',
33+
'tests/testing_tools/adapter/pytest/test_cli.py',
34+
'tests/testing_tools/adapter/pytest/test_discovery.py',
35+
]

0 commit comments

Comments
 (0)