pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

78 permanent errors in `builtins.pyi`

Open tylerlaprade opened this issue 1 year ago • 20 comments

Environment data

  • Pylance version: v2024.9.100 (pre-release) or v2024.14.1 (occurs with both)
  • OS and version: MacOS Sonoma 14.6.1
  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.2

Code Snippet

pyrightconfig.json

{
	"pythonVersion": "3.12",
	"include": ["hanaq"],
	"extraPaths": ["hanaq"],
	"ignore": [
		"**/node_modules",
		"**/__pycache__",
		"**/.*",
		"**/dist",
		"**/.vscode",
		"**/*.pyi",
		"**/__init__.py"
	],
	"exclude": ["hanaq/abacus/migrations"],
	"typeCheckingMode": "standard",
	"enableTypeIgnoreComments": false,
	"strictListInference": true,
	"strictSetInference": true,
}

Expected behavior

No errors from outside my code

Actual behavior

image

tylerlaprade avatar Sep 18 '24 19:09 tylerlaprade

Yes, these are real type errors in builtins.pyi, so pyright is correct in generating these diagnostics.

Typeshed maintainers are forced to use incompatible method overrides because the stdlib does not always honor the Liskov Substitution Principle. The typeshed CI pipelines explicitly disable a number of pyright's checks including reportIncompatibleMethodOverride and reportPrivateUsage. If you would prefer that these errors be suppressed, you could submit a bug report or a PR to the typeshed project to add # pyright: ignore comments.

erictraut avatar Sep 18 '24 19:09 erictraut

Hi @erictraut,

As per Jelle's response, those errors should not be showing up. Is there a way I can configure pyright to not show them? I tried various ways of adding the file to my ignore array, but nothing seemed to work.

Regards, Tyler

tylerlaprade avatar Sep 21 '24 03:09 tylerlaprade

Jelle is correct that if you run the pyright CLI tool on your project, you should not see errors in stub files or library files that are imported but are not themselves part of your project. Likewise, if you are using the pyright language server (or pylance) and open files that are part of your project, you won't see errors from builtins.pyi even though every source file implicitly imports from the builtins.pyi module.

However, if you explicitly open builtins.pyi (which isn't part of your project) within your editor, the language server will invoke pyright on that file using default pyright settings. I'm guessing that's what's happening here. Are you opening builtins.pyi when working on your project? If so, you will see errors in this file appear within the "problems" panel while this file is open. If you then close the file, these errors will disappear from the problems panel. This behavior isn't specific to builtins.pyi. It occurs for any ".py" or ".pyi" file that you open in your editor if that file isn't part of your project.

erictraut avatar Sep 21 '24 07:09 erictraut

Ah, I see where the confusion is. I am not opening builtins.pyi and wouldn't even know it exists if it wasn't for these persistent errors. Even with no files open at all, Pylance has been showing these 78 errors at all times since a few weeks ago. They make it hard for me to focus on actual errors that might arise since my Problems pane is full at all times.

tylerlaprade avatar Sep 21 '24 14:09 tylerlaprade

Ah, interesting. If you're seeing these all the time even when builtins.pyi isn't open, then pylance apparently thinks that builtins.pyi is part of your project. That points to a configuration issue. I'll let the pylance team help diagnose that issue with you.

erictraut avatar Sep 21 '24 16:09 erictraut

Thanks Eric! @StellaHuang95, could this ticket be reopened, please?

tylerlaprade avatar Sep 22 '24 13:09 tylerlaprade

@tylerlaprade It would be helpful for us to be able to repro this on our own machines. Could you provide the following:

  • Code sample that repros the issue. A github repo would work if that's public.
  • Logs as described here? https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#filing-an-issue

StellaHuang95 avatar Sep 23 '24 17:09 StellaHuang95

@StellaHuang95, I unfortunately cannot share my repo since it's company property, and I haven't seen this repro in a "simple" case. I did include my pyrightconfig.json in the original issue.

I was unable to past the logs because it is too many characters. Uploading image.png…

tylerlaprade avatar Sep 23 '24 19:09 tylerlaprade

You should be able to save the log to a file and then just drag it into the issue. That should tell us where the builtins.pyi errors are coming from.

rchiodo avatar Sep 23 '24 19:09 rchiodo

Sure, good idea. I set the log level to Trace and ran the Pylance: Start Logging command (as an aside, that command isn't mentioned in the docs linked above). I wasn't seeing the errors, so I F12'ed into the definition of str to open up builtins.pyi then quickly closed it. The 78 errors showed up when it opened and remained after closing it. Also, I noticed an unexpected large number of files being analyzed after that

image

pylance_2024.9.101_id_0.txt

tylerlaprade avatar Sep 23 '24 21:09 tylerlaprade

It only repro'd when you opened the file? I would guess that's this error then: https://github.com/microsoft/pylance-release/issues/5402

VS code doesn't always tell us that a file has closed. That can cause errors from recently opened files to remain visible until you restart VS code.

rchiodo avatar Sep 23 '24 21:09 rchiodo

Yes. Although that's different behavior from last week - it was previously reporting errors without opening anything.

tylerlaprade avatar Sep 24 '24 03:09 tylerlaprade

It's also possible there's another condition responsible for getting me into the "always error" mode which I'm unaware of. I just forced the trigger for the logging.

tylerlaprade avatar Sep 24 '24 03:09 tylerlaprade

Update: I just experienced the 78 errors without opening builtins.pyi at all, but unfortunately I didn't have trace-level logging enabled. Is there anything useful in here?

2024-09-23 17:12:07.210 [info] (83210) Server settings returned for workspace: file:///Users/tyler/Code/condor: {
  "autoSearchPaths": true,
  "disableLanguageServices": false,
  "openFilesOnly": false,
  "useLibraryCodeForTypes": true,
  "watchForSourceChanges": true,
  "watchForLibraryChanges": true,
  "watchForConfigChanges": true,
  "typeCheckingMode": "off",
  "diagnosticSeverityOverrides": {
    "reportShadowedImports": "warning"
  },
  "diagnosticBooleanOverrides": {
    "strictListInference": false,
    "strictDictionaryInference": false,
    "strictSetInference": false,
    "analyzeUnannotatedFunctions": true,
    "strictParameterNoneValue": true,
    "enableTypeIgnoreComments": true,
    "deprecateTypingAliases": false,
    "enableReachabilityAnalysis": false,
    "enableExperimentalFeatures": false,
    "disableBytesTypePromotions": false
  },
  "logLevel": "warn",
  "autoImportCompletions": true,
  "indexing": true,
  "completeFunctionParens": false,
  "enableExtractCodeAction": true,
  "indexOptions": {
    "packageDepths": [
      [
        "django",
        10,
        true
      ],
      [
        "rest_framework",
        10,
        true
      ],
      [
        "annoying",
        10,
        true
      ],
      [
        "syrupy",
        10,
        true
      ]
    ],
    "regenerateStdLibIndices": false,
    "localStorageUri": {
      "_key": "/users/tyler/code/condor",
      "_filePath": "/Users/tyler/Code/condor",
      "_query": "",
      "_fragment": "",
      "_originalString": "file:///Users/tyler/Code/condor",
      "_isCaseSensitive": false,
      "_formattedString": "file:///Users/tyler/Code/condor",
      "_normalizedPath": "/Users/tyler/Code/condor"
    },
    "userFileIndexingLimit": 2000
  },
  "variableInlayTypeHints": false,
  "callArgumentNameInlayHints": "off",
  "functionReturnInlayTypeHints": true,
  "pytestParametersInlayTypeHints": true,
  "importFormat": "absolute",
  "includeFileSpecs": [],
  "excludeFileSpecs": [],
  "ignoreFileSpecs": [],
  "formatOnType": true,
  "taskListTokens": [],
  "enablePytestSupport": true,
  "gotoDefinitionInStringLiteral": true,
  "remapDiagnostics": false,
  "intelliCodeEnabled": true,
  "aiCodeActions": {
    "implementAbstractClasses": false
  },
  "completionOverrideExperiment": false,
  "languageServerMode": "default",
  "pythonPath": {
    "_key": "/users/tyler/code/condor/.env/bin/python",
    "_filePath": "/Users/tyler/Code/condor/.env/bin/python",
    "_query": "",
    "_fragment": "",
    "_isCaseSensitive": false
  },
  "pythonEnvironmentName": "3.12.2 (.env venv)",
  "disableTaggedHints": false,
  "fixAll": [
    "source.convertImportFormat"
  ],
  "extraCommitChars": false,
  "autoFormatStrings": true,
  "autoIndent": true,
  "supportRestructuredText": true,
  "cacheLSPData": false,
  "reportExtraTelemetry": false,
  "supportDocstringTemplate": false,
  "nodeExecutable": "",
  "editorIndentConfig": {
    "defaultTabSequence": "    ",
    "tabSize": 4
  }
}
2024-09-23 17:12:07.211 [info] (83210) Server settings returned for workspace: undefined: {
  "autoSearchPaths": true,
  "disableLanguageServices": false,
  "openFilesOnly": false,
  "useLibraryCodeForTypes": true,
  "watchForSourceChanges": true,
  "watchForLibraryChanges": true,
  "watchForConfigChanges": true,
  "typeCheckingMode": "off",
  "diagnosticSeverityOverrides": {
    "reportShadowedImports": "warning"
  },
  "diagnosticBooleanOverrides": {
    "strictListInference": false,
    "strictDictionaryInference": false,
    "strictSetInference": false,
    "analyzeUnannotatedFunctions": true,
    "strictParameterNoneValue": true,
    "enableTypeIgnoreComments": true,
    "deprecateTypingAliases": false,
    "enableReachabilityAnalysis": false,
    "enableExperimentalFeatures": false,
    "disableBytesTypePromotions": false
  },
  "logLevel": "warn",
  "autoImportCompletions": true,
  "indexing": false,
  "completeFunctionParens": false,
  "enableExtractCodeAction": true,
  "indexOptions": {
    "packageDepths": [
      [
        "django",
        10,
        true
      ],
      [
        "rest_framework",
        10,
        true
      ],
      [
        "annoying",
        10,
        true
      ],
      [
        "syrupy",
        10,
        true
      ]
    ],
    "regenerateStdLibIndices": false,
    "userFileIndexingLimit": 2000
  },
  "variableInlayTypeHints": false,
  "callArgumentNameInlayHints": "off",
  "functionReturnInlayTypeHints": true,
  "pytestParametersInlayTypeHints": true,
  "importFormat": "absolute",
  "includeFileSpecs": [],
  "excludeFileSpecs": [],
  "ignoreFileSpecs": [],
  "formatOnType": true,
  "taskListTokens": [],
  "enablePytestSupport": true,
  "gotoDefinitionInStringLiteral": true,
  "remapDiagnostics": false,
  "intelliCodeEnabled": true,
  "aiCodeActions": {
    "implementAbstractClasses": false
  },
  "completionOverrideExperiment": false,
  "languageServerMode": "default",
  "pythonPath": {
    "_key": "/users/tyler/code/condor/.env/bin/python",
    "_filePath": "/Users/tyler/Code/condor/.env/bin/python",
    "_query": "",
    "_fragment": "",
    "_originalString": "file:///Users/tyler/Code/condor/.env/bin/python",
    "_isCaseSensitive": false,
    "_formattedString": "file:///Users/tyler/Code/condor/.env/bin/python"
  },
  "pythonEnvironmentName": "3.12.2 (.env venv)",
  "disableTaggedHints": false,
  "fixAll": [
    "source.convertImportFormat"
  ],
  "extraCommitChars": false,
  "autoFormatStrings": true,
  "autoIndent": true,
  "supportRestructuredText": true,
  "cacheLSPData": false,
  "reportExtraTelemetry": false,
  "supportDocstringTemplate": false,
  "nodeExecutable": "",
  "editorIndentConfig": {
    "defaultTabSequence": "    ",
    "tabSize": 4
  }
}
2024-09-23 17:12:09.231 [info] [Error - 5:12:09 PM] (83210) File or directory "/<default workspace root>" does not exist.
2024-09-24 09:41:56.503 [info] [Error - 9:41:56 AM] (83210) File or directory "/<default workspace root>" does not exist.
2024-09-24 14:51:57.796 [info] [Info  - 2:51:57 PM] Server process exited successfully
2024-09-24 14:52:16.376 [info] [Info  - 2:52:16 PM] (50513) Server root directory: file:///Users/tyler/.vscode/extensions/ms-python.vscode-pylance-2024.9.101/dist
2024-09-24 14:52:16.378 [info] [Info  - 2:52:16 PM] (50513) Pylance language server 2024.9.101 (pyright version 1.1.381, commit d0411a0a) starting
2024-09-24 14:52:16.383 [info] [Info  - 2:52:16 PM] (50513) Starting service instance "condor"
2024-09-24 14:52:48.614 [info] [Info  - 2:52:48 PM] (51791) Server root directory: file:///Users/tyler/.vscode/extensions/ms-python.vscode-pylance-2024.9.101/dist
2024-09-24 14:52:48.614 [info] [Info  - 2:52:48 PM] (51791) Pylance language server 2024.9.101 (pyright version 1.1.381, commit d0411a0a) starting
2024-09-24 14:52:48.620 [info] [Info  - 2:52:48 PM] (51791) Starting service instance "condor"
2024-09-24 14:57:01.488 [info] [Info  - 2:57:01 PM] Server process exited successfully
2024-09-24 14:57:11.835 [info] [Info  - 2:57:11 PM] (53767) Server root directory: file:///Users/tyler/.vscode/extensions/ms-python.vscode-pylance-2024.9.101/dist
2024-09-24 14:57:11.836 [info] [Info  - 2:57:11 PM] (53767) Pylance language server 2024.9.101 (pyright version 1.1.381, commit d0411a0a) starting
2024-09-24 14:57:11.839 [info] [Info  - 2:57:11 PM] (53767) Starting service instance "condor"

tylerlaprade avatar Sep 24 '24 21:09 tylerlaprade

Unfortunately, it needs the trace logging on. We must have analyzed the builtins.pyi for some reason.

rchiodo avatar Sep 24 '24 21:09 rchiodo

I have noticed this issue happening frequently recently. I suspect it might be caused by other VSCode extensions, as I recently added GitHub Pull Requests and GitLens to my setup. Sometimes builtins.py (and other imports) will disappear after bit, sometimes they stay indefinitely which might be an interaction with #5402

wxMichael avatar Oct 20 '24 15:10 wxMichael

I'm also seeing errors persist after I close a source file, not necessarily with builtins.py. I've confirmed in the debugger that VS Code is sometimes not sending a "file closed" message to the language server, or it sends it in a delayed manner, tens of seconds after the file was actually closed. I've tried disabling other VS Code extensions to see if they might be the cause, but that doesn't seem to be the problem. I suspect it's a regression in VS Code itself. I started to see this about two months ago.

erictraut avatar Oct 20 '24 16:10 erictraut

@wxMichael, that's great info, thanks. I use both those extensions. I assume GitLens would be the culprit, although it could be either.

tylerlaprade avatar Oct 21 '24 03:10 tylerlaprade

I just experienced the same issue as OP. As Eric described, the errors just suddenly disappeared after a long delay (minutes?). Unfortunately I don't know if I actually opened builtins.pyi beforehand, but I suspect that I did. (I had done a few "go to definitions" in the minutes prior.)

Unfortunately, I don't know how to reproduce this issue.

nmsmith avatar May 02 '25 04:05 nmsmith

I believe I'm experiencing the same issue described here.

In my case, Pylance reports type errors from files under:

~/.vscode/extensions/ms-python.vscode-pylance-*/dist/typeshed-fallback/...

Here are some details about my current setup:

  • "python.analysis.typeCheckingMode" is set to "strict".
  • "python.analysis.diagnosticMode" is set to "workspace".
  • My project uses a virtual environment located in .venv, configured via "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python".
  • I've excluded the .venv and other irrelevant paths using "python.analysis.exclude".
  • I’m not using pyrightconfig.json; all relevant settings are in .vscode/settings.json.

Even after closing the stub file, the error does not disappear.

E5presso avatar May 29 '25 12:05 E5presso