From 36b8e526a453a768eb955c0629d6f0ae8d6f0494 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Fri, 20 Oct 2023 11:50:22 -0700 Subject: [PATCH] Remove stdlib setting --- README.md | 2 +- bundled/tool/lsp_server.py | 7 +- package.json | 6 -- package.nls.json | 3 +- src/common/settings.ts | 4 - src/test/python_tests/test_linting.py | 98 ------------------- .../tests/common/settings.unit.test.ts | 13 --- 7 files changed, 4 insertions(+), 129 deletions(-) diff --git a/README.md b/README.md index 4fd081dc..ee308e2e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ A Visual Studio Code extension with support for the `pylint` linter. The extension ships with `pylint=3.0.1`. Note: + - This extension is supported for all [actively supported versions](https://devguide.python.org/#status-of-python-branches) of the `Python` language (i.e., Python >= 3.8). - By default, this extension uses the shipped `pylint` version. However, you can use `pylint` from your environment by setting `pylint.importStrategy` to `fromEnvironment`. Alternatively, you can use a custom `pylint` executable by setting `pylint.path`. - Minimum supported version of `pylint` is `2.12.2`. @@ -26,7 +27,6 @@ If you want to disable pylint, you can [disable this extension](https://code.vis | pylint.showNotification | `off` | Setting to control when a notification is shown. | | pylint.lintOnChange | `false` | (experimental) Setting to control linting on change feature. | | pylint.ignorePatterns | `[]` | Glob patterns used to exclude files and directories from being linted. | -| pylint.includeStdLib | `false` | Controls whether to perform linting on Python's standard library files or directories. | ## Commands diff --git a/bundled/tool/lsp_server.py b/bundled/tool/lsp_server.py index 9160f0f2..5617cef3 100644 --- a/bundled/tool/lsp_server.py +++ b/bundled/tool/lsp_server.py @@ -577,7 +577,6 @@ def _get_global_defaults(): "importStrategy": GLOBAL_SETTINGS.get("importStrategy", "useBundled"), "showNotifications": GLOBAL_SETTINGS.get("showNotifications", "off"), "extraPaths": GLOBAL_SETTINGS.get("extraPaths", []), - "includeStdLib": False, } @@ -683,13 +682,11 @@ def _run_tool_on_document( log_warning(f"Skipping notebook cells [Not Supported]: {str(document.uri)}") return None - if not settings["includeStdLib"] and utils.is_stdlib_file(document.path): + if utils.is_stdlib_file(document.path): log_warning( f"Skipping standard library file (stdlib excluded): {document.path}" ) - log_warning( - "You can include stdlib files by setting `pylint.includeStdLib` to true." - ) + return None if utils.is_match(settings["ignorePatterns"], document.path): diff --git a/package.json b/package.json index 8b27c1da..06ae3b71 100644 --- a/package.json +++ b/package.json @@ -200,12 +200,6 @@ ], "scope": "machine", "type": "string" - }, - "pylint.includeStdLib": { - "default": false, - "description": "%settings.includeStdLib.description%", - "scope": "resource", - "type": "boolean" } } }, diff --git a/package.nls.json b/package.nls.json index f48fd7aa..98ab0cae 100644 --- a/package.nls.json +++ b/package.nls.json @@ -15,6 +15,5 @@ "settings.showNotifications.off.description": "All notifications are turned off, any errors or warning are still available in the logs.", "settings.showNotifications.onError.description": "Notifications are shown only in the case of an error.", "settings.showNotifications.onWarning.description": "Notifications are shown for errors and warnings.", - "settings.showNotifications.always.description": "Notifications are shown for anything that the server chooses to show.", - "settings.includeStdLib.description": "Controls whether to filter out files from standard library from being linted." + "settings.showNotifications.always.description": "Notifications are shown for anything that the server chooses to show." } diff --git a/src/common/settings.ts b/src/common/settings.ts index 6ab5d8f6..073be5ad 100644 --- a/src/common/settings.ts +++ b/src/common/settings.ts @@ -24,7 +24,6 @@ export interface ISettings { interpreter: string[]; importStrategy: string; showNotifications: string; - includeStdLib: boolean; extraPaths: string[]; } @@ -138,7 +137,6 @@ export async function getWorkspaceSettings( importStrategy: config.get('importStrategy', 'useBundled'), showNotifications: config.get('showNotifications', 'off'), extraPaths: resolveVariables(extraPaths, workspace), - includeStdLib: config.get('includeStdLib', false), }; return workspaceSetting; } @@ -170,7 +168,6 @@ export async function getGlobalSettings(namespace: string, includeInterpreter?: importStrategy: getGlobalValue(config, 'importStrategy', 'fromEnvironment'), showNotifications: getGlobalValue(config, 'showNotifications', 'off'), extraPaths: getGlobalValue(config, 'extraPaths', []), - includeStdLib: config.get('includeStdLib', false), }; return setting; } @@ -190,7 +187,6 @@ export function checkIfConfigurationChanged(e: ConfigurationChangeEvent, namespa `${namespace}.importStrategy`, `${namespace}.showNotifications`, `${namespace}.ignorePatterns`, - `${namespace}.includeStdLib`, `${namespace}.lintOnChange`, 'python.analysis.extraPaths', ]; diff --git a/src/test/python_tests/test_linting.py b/src/test/python_tests/test_linting.py index 0911f9c7..f3d5349a 100644 --- a/src/test/python_tests/test_linting.py +++ b/src/test/python_tests/test_linting.py @@ -480,104 +480,6 @@ def _handler(params): assert_that(actual, is_(expected)) -@pytest.mark.parametrize("value", [True, False], ids=["include-stdlib", "skip-stdlib"]) -def test_stdlib_filtering(value: bool): - """Test to ensure stdlib filtering setting works.""" - contents = TEST_FILE_PATH.read_text(encoding="utf-8") - - actual = [] - with session.LspSession() as ls_session: - default_init = defaults.vscode_initialize_defaults() - init_options = default_init["initializationOptions"] - init_options["settings"][0]["includeStdLib"] = value - init_options["globalSettings"]["includeStdLib"] = value - ls_session.initialize(default_init) - - # trick pylint into thinking the file is stdlib file - FAKE_TEST_URI = utils.as_uri( - str(pathlib.Path(pytest.__file__).parent / "sample.py") - ) - - done = Event() - - def _handler(params): - nonlocal actual - actual = params - done.set() - - ls_session.set_notification_callback(session.PUBLISH_DIAGNOSTICS, _handler) - - ls_session.notify_did_open( - { - "textDocument": { - "uri": FAKE_TEST_URI, - "languageId": "python", - "version": 1, - "text": contents, - } - } - ) - - # wait for some time to receive all notifications - done.wait(TIMEOUT) - - expected = { - "uri": FAKE_TEST_URI, - "diagnostics": [ - { - "range": { - "start": {"line": 0, "character": 0}, - "end": {"line": 0, "character": 0}, - }, - "message": "Missing module docstring", - "severity": 3, - "code": "C0114:missing-module-docstring", - "codeDescription": { - "href": f"{DOCUMENTATION_HOME}/convention/missing-module-docstring.html" - }, - "source": LINTER["name"], - }, - { - "range": { - "start": {"line": 2, "character": 6}, - "end": { - "line": 2, - "character": 7, - }, - }, - "message": "Undefined variable 'x'", - "severity": 1, - "code": "E0602:undefined-variable", - "codeDescription": { - "href": f"{DOCUMENTATION_HOME}/error/undefined-variable.html" - }, - "source": LINTER["name"], - }, - { - "range": { - "start": {"line": 0, "character": 0}, - "end": { - "line": 0, - "character": 10, - }, - }, - "message": "Unused import sys", - "severity": 2, - "code": "W0611:unused-import", - "codeDescription": { - "href": f"{DOCUMENTATION_HOME}/warning/unused-import.html" - }, - "source": LINTER["name"], - }, - ], - } - - if value: - assert_that(actual, is_(expected)) - else: - assert_that(actual, is_({"uri": FAKE_TEST_URI, "diagnostics": []})) - - @pytest.mark.parametrize( "patterns", [ diff --git a/src/test/ts_tests/tests/common/settings.unit.test.ts b/src/test/ts_tests/tests/common/settings.unit.test.ts index 7567bdd0..714f82dc 100644 --- a/src/test/ts_tests/tests/common/settings.unit.test.ts +++ b/src/test/ts_tests/tests/common/settings.unit.test.ts @@ -83,10 +83,6 @@ suite('Settings Tests', () => { .setup((c) => c.get('ignorePatterns', [])) .returns(() => []) .verifiable(TypeMoq.Times.atLeastOnce()); - configMock - .setup((c) => c.get('includeStdLib', false)) - .returns(() => false) - .verifiable(TypeMoq.Times.atLeastOnce()); pythonConfigMock .setup((c) => c.get('linting.pylintArgs', [])) @@ -113,7 +109,6 @@ suite('Settings Tests', () => { assert.deepStrictEqual(settings.workspace, workspace1.uri.toString()); assert.deepStrictEqual(settings.extraPaths, []); assert.deepStrictEqual(settings.ignorePatterns, []); - assert.deepStrictEqual(settings.includeStdLib, false); configMock.verifyAll(); pythonConfigMock.verifyAll(); @@ -163,10 +158,6 @@ suite('Settings Tests', () => { .setup((c) => c.get('ignorePatterns', [])) .returns(() => []) .verifiable(TypeMoq.Times.atLeastOnce()); - configMock - .setup((c) => c.get('includeStdLib', false)) - .returns(() => false) - .verifiable(TypeMoq.Times.atLeastOnce()); pythonConfigMock .setup((c) => c.get('linting.pylintArgs', [])) @@ -255,10 +246,6 @@ suite('Settings Tests', () => { .setup((c) => c.get('ignorePatterns', [])) .returns(() => []) .verifiable(TypeMoq.Times.atLeastOnce()); - configMock - .setup((c) => c.get('includeStdLib', false)) - .returns(() => false) - .verifiable(TypeMoq.Times.atLeastOnce()); pythonConfigMock .setup((c) => c.get('linting.pylintArgs', []))