microsoft / pyright

Static Type Checker for Python
Other
13.37k stars 1.46k forks source link

Crash with `--threads` and `--pythonversion` #8775

Closed Avasam closed 2 months ago

Avasam commented 2 months ago

Describe the bug When the flags --threads and --pythonversion are used together, pyright crashes.

Code or Screenshots Run npx -y pyright@1.1.376 --pythonversion=X.X --threads

The python version doesn't seem to matter. It can even be an empty file, (I did npx -y pyright@1.1.376 testfile.py --pythonversion=3.9 --threads)

e:\Users\Avasam\Documents\Git\setuptools\testfile.py
  e:\Users\Avasam\Documents\Git\setuptools\testfile.py: error: An internal error occurred while parsing file "e:\Users\Avasam\Documents\Git\setuptools\testfile.py": TypeError: n.isLessThan is not a function
      at S._isStdlibTypeshedStubValidForVersion (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\importResolver.ts:2002:35)
      at S._getStdlibTypeshedPath (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\importResolver.ts:1963:19)
      at S._findTypeshedPath (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\importResolver.ts:1770:31)
      at S._resolveBestAbsoluteImport (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\importResolver.ts:1564:47)
      at S._resolveImportStrict (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\importResolver.ts:909:37)
      at S.resolveImportInternal (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\importResolver.ts:539:35)
      at S.resolveImport (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\importResolver.ts:161:21)
      at resolveAndAddIfNotSelf (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\sourceFile.ts:1337:49)
      at t.SourceFile._resolveImports (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\sourceFile.ts:1366:36)
      at callback (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\sourceFile.ts:681:47)
      at a.timeOperation (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\common\timing.ts:44:28)
      at callback (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\sourceFile.ts:680:48)
      at t.LogTracker.log (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\common\logTracker.ts:49:20)
      at t.SourceFile.parse (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\sourceFile.ts:621:33)
      at F._parseFile (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\program.ts:1658:36)
      at F._bindFile (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\program.ts:1739:14)
      at callback (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\program.ts:1917:36)
      at t.LogTracker.log (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\common\logTracker.ts:49:20)
      at F._checkTypes (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\program.ts:1895:33)
      at callback (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\program.ts:632:30)
      at callback (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\typeEvaluator.ts:653:20)
      at a.runWithCancellationToken [as timeOperation] (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\common\timing.ts:44:28)
      at F._runEvaluatorWithCancellationToken (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\program.ts:1045:41)
      at F.analyze (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\program.ts:620:21)
      at analyzeProgram (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\analysis.ts:57:33)
      at t.BackgroundAnalysisProgram.startAnalysis (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\backgroundAnalysisProgram.ts:157:16)
      at Timeout._onTimeout (C:\Users\Avasam\AppData\Local\npm-cache\_npx\9d1f70f3ffbfbe3b\node_modules\pyright\dist\pyright-internal\src\analyzer\service.ts:1866:67)
      at listOnTimeout (node:internal/timers:569:17)
      at processTimers (node:internal/timers:512:7)
1 error, 0 warnings, 0 informations 

VS Code extension or command-line pyright: 1.1.376

erictraut commented 2 months ago

Thanks for the bug report. This will be fixed in the next release.

In the meantime, you can avoid the crash if you configure the pythonVersion in your config file rather than passing it as a CLI option. Or you can skip the --threads option.

erictraut commented 2 months ago

This is addressed in pyright 1.1.377.