Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyright behavior changes after adding even an empty pyrightconfig.json #6446

Open
fireattack opened this issue Sep 25, 2024 · 5 comments
Open
Assignees
Labels
needs repro Issue has not been reproduced yet settings-override Feedback that pyrightconfig.json is taking precedence

Comments

@fireattack
Copy link

fireattack commented Sep 25, 2024

Environment data

  • Pylance version: v2024.9.2
  • OS and version: Windows 10
  • Python version: 3.12.1 x64 Official

Repro Steps

  1. create a temp.py file with
import re

def test(s):
    number = re.search(r'(\d+)', s)[1]
  1. Observe there is no warning or whatsoever from pyright.
  2. Create a pyrightconfig.json file with {}.
  3. Switch back to temp.py again.

Expected behavior

The pyright checker behavior should not change (i.e. no warning).

Actual behavior

pyright now shows an error level warning of reportOptionalSubscript.

Logs

log.log


Above is just an example; when local pyrightconfig.json is enabled, it reports a lot more errors than default Pylance would (I tested with VS Code Insider with empty user settings.json).

My gut feeling is this issue is caused by that Pylance by default uses some non-standard settings which got entirely overwritten by the local pyrightconfig.json even if it's empty (instead of merging the two).

The problem is I cannot find where these settings are located.

The only thing I found is C:\Users\ikena\.vscode-insiders\extensions\ms-python.vscode-pylance-2024.9.2\dist\schemas\pyrightconfig.schema.json but it does not have anything different from pyright default (e.g. it says reportOptionalSubscript is default to error:

    "reportOptionalSubscript": {
      "$ref": "#/definitions/diagnostic",
      "title": "Controls reporting of attempts to subscript (index) a variable with Optional type",
      "default": "error"
    },

).

This makes reduplicating Pylance's default behavior (which I WANT) in a workspace where a pyrightconfig.json was introduced for other reasons (like adding exclude) very difficult.

Thanks.

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 25, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Sep 25, 2024

Thanks for the issue. Settings for pylance and pyright are really confusing.

Defaults for pylance are described here:

https://github.com/microsoft/pylance-release?tab=readme-ov-file#settings-and-customization

You're correct, specifying an empty pyrightconfig.json actually sets a number of settings to their default for a pyrightconfig.json. Those are described here:
https://microsoft.github.io/pyright/#/configuration?id=pyright-configuration

The reason why an empty pyrightconfig.json overrides everything is described here:
https://github.com/microsoft/pylance-release/wiki/Settings.json-overridden-by-Pyrightconfig.json-or-Pyproject.toml

If you want to duplicate the defaults for pylance in your pyrightconfig.json, you'd have something like so:

{
    "typeCheckingMode": "off",
    "reportShadowedImports": "warning",
}

While also leaving your settings.json blank. The pyrightconfig.json only overrides pyright settable settings in the settings.json so most of the defaults would still apply. typeCheckingMode and reportShadowedImports are I believe the only settings that are defaulted differently.

I think we need to have a better explanation for all of this somewhere.

@heejaechang
Copy link
Contributor

heejaechang commented Sep 25, 2024

ya, we should write that pyright and pylance have different defaults for some settings and having pyrightconfig.json/pyproject.toml (even empty one) will change which default we will use and links to each defaults.

@Hnasar
Copy link

Hnasar commented Sep 25, 2024

(just wanted to note that this was also discussed in #6373) Since this behavior seems to be confusing lots of people, it would be great to consider reverting the behavior rather than just relying on documentation of this footgun.

@rchiodo rchiodo added the settings-override Feedback that pyrightconfig.json is taking precedence label Sep 25, 2024
@taldcroft
Copy link

taldcroft commented Sep 26, 2024

Strong 👍 to making the behavior more predictable and consistent with the way that configuration files usually work. I wasted nearly an hour tracking down what was happening because it is so unexpected and because it is embedded in VS code (introducing some uncertainty in where the problem lies).

My use case is that I want to exclude certain files from Pylance analysis on a per-project basis. That seems like very common thing to do, using something like:

{
    "ignore": [
        "**/*.ipynb",
    ]
}

It is COMPLETELY UNEXPECTED that this innocuous configuration would override any unrelated python.analysis settings I have in VS code. In particular it seems to be enabling basic or strict type checking, which is not what I want.

@fireattack
Copy link
Author

fireattack commented Sep 26, 2024

Thanks for all the valuable discussion. Especially the default values pylance uses: which solves my immediate problem by adding them to my pyrightconfig.json. I think this probably should be surfaced more prominently somewhere in the official doc.

I don't mind pyrightconfig.json having highest priority by default in principle from a project collaboration perspective.

But some options around it, and even better, providing a way to merge the two at option-level (instead of overwriting entirely) would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet settings-override Feedback that pyrightconfig.json is taking precedence
Projects
None yet
Development

No branches or pull requests

5 participants