Closed ierezell closed 1 year ago
Pylance is built on top of pyright, so they should give the same results.
There are a few reasons why you might see small differences:
It looks like you're trying to use many of the strict type checking features including the "reportUnknownXXX" diagnostic checks. These checks rely on complete type information from libraries. If you are consuming any libraries that are not fully and accurately typed, you will likely run into problems. We normally recommend against using "useLibraryCodeForTypes" with type checking — and especially with strict-mode type checking — because it relies on type inference, and that often results in incomplete or inaccurate types.
Hi @erictraut,
Thanks a lot for the complete response.
Indeed the problem came from microsoft/python-type-stubs
missing.
Adding that (especially the pandas one) removed all the problems related with pandas (most of them were unknwonType).
Now I have the same output in the tab and in the CLI.
Have a great day.
Hello, Sorry to bump this old thread but the error came again...
I'm trying to use CI/CD (Pyright in github actions) and I do not have the same results in command line and in vscode.
My structure is :
MyProject
.venv
production (some untyped code to ignore)
packages
MyPackage1
MyPackage2
MyPackage3
typings
python-type-stubs (submodule)
pyrightconfig.json
The pyrightconfig.json
is :
{
"enableTypeIgnoreComments": true,
"exclude": [],
"executionEnvironments": [],
"extraPaths": [
"typings/python-type-stubs"
],
"ignore": [
"production",
"typings",
".venv/*"
],
"pythonVersion": "3.8",
"include": [],
"strict": [],
"strictDictionaryInference": true,
"strictListInference": true,
"strictParameterNoneValue": false,
"strictParametererrorValue": true,
"strictSetInference": true,
"stubPath": "",
"typeCheckingMode": "strict",
"typeshedPath": "",
"useLibraryCodeForTypes": true,
"venv": ".venv",
"venvPath": ".",
"verboseOutput": false,
"reportUnusedExpression": "error",
"reportAssertAlwaysTrue": "error",
"reportCallInDefaultInitializer": "error",
"reportConstantRedefinition": "error",
"reportDuplicateImport": "error",
"reportFunctionMemberAccess": "error",
"reportGeneralTypeIssues": "error",
"reportImplicitStringConcatenation": "error",
"reportImportCycles": "error",
"reportIncompatibleMethodOverride": "none",
"reportIncompatibleVariableOverride": "error",
"reportIncompleteStub": "error",
"reportInconsistentConstructor": "error",
"reportInvalidStringEscapeSequence": "error",
"reportInvalidStubStatement": "error",
"reportInvalidTypeVarUse": "error",
"reportMissingImports": "error",
"reportMissingModuleSource": "error",
"reportMissingParameterType": "error",
"reportMissingTypeArgument": "error",
"reportMissingTypeStubs": "none",
"reportOptionalCall": "error",
"reportOptionalContextManager": "error",
"reportOptionalIterable": "error",
"reportOptionalMemberAccess": "error",
"reportOptionalOperand": "error",
"reportOptionalSubscript": "error",
"reportOverlappingOverload": "error",
"reportPrivateImportUsage": "error",
"reportPrivateUsage": "none",
"reportPropertyTypeMismatch": "error",
"reportSelfClsParameterName": "error",
"reportTypedDictNotRequiredAccess": "error",
"reportUnboundVariable": "error",
"reportUndefinedVariable": "error",
"reportUninitializedInstanceVariable": "error",
"reportUnknownArgumentType": "error",
"reportUnknownLambdaType": "error",
"reportUnknownMemberType": "none",
"reportUnknownParameterType": "error",
"reportUnknownVariableType": "error",
"reportUnnecessaryCast": "error",
"reportUnnecessaryComparison": "error",
"reportUnnecessaryIsInstance": "none",
"reportUnnecessaryTypeIgnoreComment": "none",
"reportUnsupportedDunderAll": "error",
"reportUntypedBaseClass": "error",
"reportUntypedClassDecorator": "error",
"reportUntypedFunctionDecorator": "none",
"reportUntypedNamedTuple": "error",
"reportUnusedCallResult": "none",
"reportUnusedClass": "error",
"reportUnusedCoroutine": "error",
"reportUnusedFunction": "none",
"reportUnusedImport": "error",
"reportMissingSuperCall": "none",
"reportMatchNotExhaustive": "error",
"reportUnusedVariable": "error",
"reportWildcardImportFromLibrary": "error",
}
I have no error in the "problem" tab in vscode but 26 appears when running pyright with :
pyright .
or pyright ./packages/mypackage1
The errors are mostly related to pandas like :
error: Type of "df" is unknown (reportUnknownVariableType)
Cannot access member "dropna" for type "TextFileReader"
(mostly coming from pandas.read_csv())
Hovering with the mouse in vscode indicate that the variable (df = pd.read_csv(reject_file)
) is of type DataFrame.
Thanks in advance for any help
Have a great day.
I tried to solve the problem, and I'm using the latest (master branch) version of python-type-stubs. Still getting the same error... Either pyright is not using the additional typings, or pylance is doing something more behind the scene.
In your settings you could try pointing directly to the stubs that pylance shipped with. just need to find where the extension installed (can probably see it in the output logs)
in settings.json
python.analysis.stubPath = path to pylance stubs
Hello @bschnurr, thanks for the fast reply.
I do not have any python.analysis.xxxx
in my vscode config, all is in a pyrightconfig.json
file at the root of the repo.
As discussed above (https://github.com/microsoft/pylance-release/issues/2255#issuecomment-1013975276) I added python-type-stubs as it's exactly the same as the one used by pylance and this helped to have exactly the same behaviour between pylance and pyright CLI (which was the case before).
Maybe it's just pylance that is not using the same pyright version (as point 3 of the comment) ?
I'm cloning it also when doing my ci/cd so I can replicate the same behavior as vscode/pylance in my github action.
I tried to add the stub file as you said, it change nothing for pylance (as it should be the same as used by default) and I still have the same errors in pyright.
New config is :
"enableTypeIgnoreComments": true,
"exclude": [],
"executionEnvironments": [],
"extraPaths": [
"./typings/python-type-stubs"
],
"ignore": [],
"include": [
"./packages"
],
"strict": [],
"strictDictionaryInference": true,
"strictListInference": true,
"strictParameterNoneValue": false,
"strictParametererrorValue": true,
"strictSetInference": true,
"stubPath": "./typings/python-type-stubs",
"typeCheckingMode": "strict",
"typeshedPath": "",
"useLibraryCodeForTypes": true,
"venv": ".venv",
"venvPath": ".",
"verboseOutput": false,
"pythonVersion": "3.8",
"repportXXXXX": "true or false"
I also tried to change exclude, include, extraPaths but without success.
Pyright when running is reading this config file (pyrightconfig.json) as I can see it in the output. So it's the same config as Pylance should have.
It find all the files but raise typing errors that pylance does not. They're mostly errors that should be fixed by python-type-stubs.
I tried pyright 1.1.236 and then 1.1.235 (as it seems to be the one used by pylance) and both raise the same problems Thanks for your time and help
still an issue with latest pyright/pylance?
Hello @bschnurr,
I re-installed my venv from scratch and pull all latest python-type-stubs
after reading the comment and it seems I still have differences between the two.
Could be from my end though (maybe missing a small dependency or the last night version of something)... but I gave up on having the CI as it didn't give the same results and I changed a bit my workflow to adapt to that but it's okay :)
Environment data
A poetry project with a
pyrightconfig.json
. There is no.vscode
withsettings.json
nor any config in thepyproject.toml
Expected behaviour
Having the same problems in the "problem" tab and when running
pyright
by handActual behaviour
I fixed all the problems in the "problems" tab but when running pre-commit the pyright check didn't pass... So I tried to run it by hand (
poetry run pyright
) and indeed, pyright (by hand) gives "new" errors (not shown in the problems tab)Pyright config
Logs
Code Snippet / Additional information