Skip to content

Commit 412e8c8

Browse files
l0lawrenceCopilotCopilot
authored andcommitted
verifytypes (Azure#46524)
* testing fix Co-authored-by: Copilot <copilot@github.com> * verbose output * we dont support 3.9 anymore * update verifytypes pyright * add guard * Revert unrelated pyproject.toml license changes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <copilot@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7bb2c3e commit 412e8c8

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

eng/tools/azure-sdk-tools/azpysdk/verifytypes.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ci_tools.functions import get_pip_command
1919
from ci_tools.logging import logger
2020

21-
PYRIGHT_VERSION = "1.1.287"
21+
PYRIGHT_VERSION = "1.1.407"
2222
REPO_ROOT = discover_repo_root()
2323

2424

@@ -199,7 +199,21 @@ def get_type_complete_score(
199199
f"Running verifytypes failed: {e.stderr}. See https://aka.ms/python/typing-guide for information."
200200
)
201201
return -1.0
202-
report = json.loads(e.output)
202+
try:
203+
report = json.loads(e.output)
204+
except (json.JSONDecodeError, TypeError):
205+
logger.error(
206+
f"pyright --verifytypes exited with code 1 but did not produce valid JSON output.\n"
207+
f"stdout: {e.output}\n"
208+
f"stderr: {e.stderr}\n"
209+
f"Re-running without --outputjson for diagnostic output..."
210+
)
211+
non_json_commands = [c for c in commands[1:] if c != "--outputjson"] + ["--verbose"]
212+
diag = self.run_venv_command(executable, non_json_commands, cwd, check=False)
213+
logger.error(f"Diagnostic pyright stdout:\n{diag.stdout}")
214+
if diag.stderr:
215+
logger.error(f"Diagnostic pyright stderr:\n{diag.stderr}")
216+
return -1.0
203217
if check_pytyped:
204218
pytyped_present = report["typeCompleteness"].get("pyTypedPath", None)
205219
if not pytyped_present:
@@ -208,5 +222,19 @@ def get_type_complete_score(
208222
return report["typeCompleteness"]["completenessScore"]
209223

210224
# library scores 100%
211-
report = json.loads(response.stdout)
225+
try:
226+
report = json.loads(response.stdout)
227+
except (json.JSONDecodeError, TypeError):
228+
logger.error(
229+
f"pyright --verifytypes exited successfully but did not produce valid JSON output.\n"
230+
f"stdout: {response.stdout}\n"
231+
f"stderr: {response.stderr}\n"
232+
f"Re-running without --outputjson for diagnostic output..."
233+
)
234+
non_json_commands = [c for c in commands[1:] if c != "--outputjson"] + ["--verbose"]
235+
diag = self.run_venv_command(executable, non_json_commands, cwd, check=False)
236+
logger.error(f"Diagnostic pyright stdout:\n{diag.stdout}")
237+
if diag.stderr:
238+
logger.error(f"Diagnostic pyright stderr:\n{diag.stderr}")
239+
return -1.0
212240
return report["typeCompleteness"]["completenessScore"]

pyrightconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"reportTypeCommentUsage": true,
33
"reportMissingImports": false,
4-
"pythonVersion": "3.9"
4+
"pythonVersion": "3.10"
55
}

0 commit comments

Comments
 (0)