diff --git a/docs/command-line.md b/docs/command-line.md index 7b67d21ab006..af81d822512c 100644 --- a/docs/command-line.md +++ b/docs/command-line.md @@ -6,27 +6,27 @@ Pyright can be run as either a VS Code extension or as a node-based command-line | Flag | Description | | :--------------------------------- | :--------------------------------------------------- | -| --createstub `` | Create type stub file(s) for import | -| --dependencies | Emit import dependency information | -| -h, --help | Show help message | -| --ignoreexternal | Ignore external imports for --verifytypes | -| --level | Minimum diagnostic level (error or warning) | -| --outputjson | Output results in JSON format | -| -p, --project `` | Use the configuration file at this location | -| --pythonpath `` | Path to the Python interpreter (2) | -| --pythonplatform `` | Analyze for platform (Darwin, Linux, Windows) | -| --pythonversion `` | Analyze for version (3.3, 3.4, etc.) | -| --skipunannotated | Skip type analysis of unannotated functions | -| --stats | Print detailed performance stats | -| -t, --typeshedpath `` | Use typeshed type stubs at this location (3) | -| --threads | Use up to N threads to parallelize type checking (4) | -| -v, --venvpath `` | Directory that contains virtual environments (5) | -| --verbose | Emit verbose diagnostics | -| --verifytypes `` | Verify completeness of types in py.typed package | -| --version | Print pyright version and exit | -| --warnings | Use exit code of 1 if warnings are reported | -| -w, --watch | Continue to run and watch for changes (6) | -| - | Read file or directory list from stdin | +| --createstub `` | Create type stub file(s) for import | +| --dependencies | Emit import dependency information | +| -h, --help | Show help message | +| --ignoreexternal | Ignore external imports for --verifytypes | +| --level | Minimum diagnostic level (error or warning) | +| --outputjson | Output results in JSON format | +| -p, --project `` | Use the configuration file at this location | +| --pythonpath `` | Path to the Python interpreter (2) | +| --pythonplatform `` | Analyze for platform (Darwin, Linux, Windows, iOS, Android) | +| --pythonversion `` | Analyze for version (3.3, 3.4, etc.) | +| --skipunannotated | Skip type analysis of unannotated functions | +| --stats | Print detailed performance stats | +| -t, --typeshedpath `` | Use typeshed type stubs at this location (3) | +| --threads | Use up to N threads to parallelize type checking (4) | +| -v, --venvpath `` | Directory that contains virtual environments (5) | +| --verbose | Emit verbose diagnostics | +| --verifytypes `` | Verify completeness of types in py.typed package | +| --version | Print pyright version and exit | +| --warnings | Use exit code of 1 if warnings are reported | +| -w, --watch | Continue to run and watch for changes (6) | +| - | Read file or directory list from stdin | (1) If specific files are specified on the command line, it overrides the files or directories specified in the pyrightconfig.json or pyproject.toml file. diff --git a/docs/configuration.md b/docs/configuration.md index 098e9d992ba9..299c1eb034d0 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -34,7 +34,7 @@ The following settings control the *environment* in which Pyright will check for - **pythonVersion** [string, optional]: Specifies the version of Python that will be used to execute the source code. The version should be specified as a string in the format "M.m" where M is the major version and m is the minor (e.g. `"3.0"` or `"3.6"`). If a version is provided, pyright will generate errors if the source code makes use of language features that are not supported in that version. It will also tailor its use of type stub files, which conditionalizes type definitions based on the version. If no version is specified, pyright will use the version of the current python interpreter, if one is present. -- **pythonPlatform** [string, optional]: Specifies the target platform that will be used to execute the source code. Should be one of `"Windows"`, `"Darwin"`, `"Linux"`, or `"All"`. If specified, pyright will tailor its use of type stub files, which conditionalize type definitions based on the platform. If no platform is specified, pyright will use the current platform. +- **pythonPlatform** [string, optional]: Specifies the target platform that will be used to execute the source code. Should be one of `"Windows"`, `"Darwin"`, `"Linux"`, `"iOS"`, `"Android"`, or `"All"`. If specified, pyright will tailor its use of type stub files, which conditionalize type definitions based on the platform. If no platform is specified, pyright will use the current platform. - **executionEnvironments** [array of objects, optional]: Specifies a list of execution environments (see [below](configuration.md#execution-environment-options)). Execution environments are searched from start to finish by comparing the path of a source file with the root path specified in the execution environment. diff --git a/packages/pyright-internal/src/analyzer/staticExpressions.ts b/packages/pyright-internal/src/analyzer/staticExpressions.ts index 7f5edf237ea7..80eac94c0d48 100644 --- a/packages/pyright-internal/src/analyzer/staticExpressions.ts +++ b/packages/pyright-internal/src/analyzer/staticExpressions.ts @@ -345,6 +345,15 @@ function _getExpectedPlatformNameFromPlatform(execEnv: ExecutionEnvironment): st return 'win32'; } else if (execEnv.pythonPlatform === PythonPlatform.Linux) { return 'linux'; + } else if (execEnv.pythonPlatform === PythonPlatform.iOS) { + return 'ios'; + } else if (execEnv.pythonPlatform === PythonPlatform.Android) { + // Python >= 3.13 reports Android as 'android', earlier used to report it as 'linux' + if (execEnv.pythonVersion.major === 3 && execEnv.pythonVersion.minor >= 13) { + return 'android'; + } else { + return 'linux'; + } } return undefined; @@ -357,6 +366,10 @@ function _getExpectedOsNameFromPlatform(execEnv: ExecutionEnvironment): string | return 'nt'; } else if (execEnv.pythonPlatform === PythonPlatform.Linux) { return 'posix'; + } else if (execEnv.pythonPlatform === PythonPlatform.iOS) { + return 'posix'; + } else if (execEnv.pythonPlatform === PythonPlatform.Android) { + return 'posix'; } return undefined; diff --git a/packages/pyright-internal/src/common/commandLineOptions.ts b/packages/pyright-internal/src/common/commandLineOptions.ts index 588ae97c33f4..c8de1333eae5 100644 --- a/packages/pyright-internal/src/common/commandLineOptions.ts +++ b/packages/pyright-internal/src/common/commandLineOptions.ts @@ -64,8 +64,8 @@ export class CommandLineConfigOptions { // Name for the virtual environment. pythonEnvironmentName?: string | undefined; - // Python platform indicator (darwin, linux, win32) - pythonPlatform?: 'Darwin' | 'Linux' | 'Windows' | undefined; + // Python platform indicator (darwin, linux, win32, ios, android) + pythonPlatform?: 'Darwin' | 'Linux' | 'Windows' | 'iOS' | 'Android' | undefined; // Python version string (3.3, 3.4, etc.) pythonVersion?: PythonVersion | undefined; diff --git a/packages/pyright-internal/src/common/configOptions.ts b/packages/pyright-internal/src/common/configOptions.ts index 7cb1af20ff30..484469ee1399 100644 --- a/packages/pyright-internal/src/common/configOptions.ts +++ b/packages/pyright-internal/src/common/configOptions.ts @@ -35,6 +35,8 @@ export enum PythonPlatform { Darwin = 'Darwin', Windows = 'Windows', Linux = 'Linux', + iOS = 'iOS', + Android = 'Android', } export class ExecutionEnvironment { diff --git a/packages/pyright-internal/src/common/fullAccessHost.ts b/packages/pyright-internal/src/common/fullAccessHost.ts index b8adae491982..f881b25b589c 100644 --- a/packages/pyright-internal/src/common/fullAccessHost.ts +++ b/packages/pyright-internal/src/common/fullAccessHost.ts @@ -58,6 +58,8 @@ export class LimitedAccessHost extends NoAccessHost { return PythonPlatform.Linux; } else if (process.platform === 'win32') { return PythonPlatform.Windows; + } else if (process.platform === 'android') { + return PythonPlatform.Android; } return undefined; diff --git a/packages/pyright-internal/src/pyright.ts b/packages/pyright-internal/src/pyright.ts index a1d95dd96906..981246b7687b 100644 --- a/packages/pyright-internal/src/pyright.ts +++ b/packages/pyright-internal/src/pyright.ts @@ -296,11 +296,12 @@ async function processArgs(): Promise { } if (args.pythonplatform) { - if (args.pythonplatform === 'Darwin' || args.pythonplatform === 'Linux' || args.pythonplatform === 'Windows') { + if (args.pythonplatform === 'Darwin' || args.pythonplatform === 'Linux' || args.pythonplatform === 'Windows' || + args.pythonplatform === 'iOS' || args.pythonplatform === 'Android') { options.configSettings.pythonPlatform = args.pythonplatform; } else { console.error( - `'${args.pythonplatform}' is not a supported Python platform; specify Darwin, Linux, or Windows` + `'${args.pythonplatform}' is not a supported Python platform; specify Darwin, Linux, Windows, iOS, or Android.` ); return ExitStatus.ParameterError; } @@ -1129,7 +1130,7 @@ function printUsage() { ' --level Minimum diagnostic level (error or warning)\n' + ' --outputjson Output results in JSON format\n' + ' -p,--project Use the configuration file at this location\n' + - ' --pythonplatform Analyze for a specific platform (Darwin, Linux, Windows)\n' + + ' --pythonplatform Analyze for a specific platform (Darwin, Linux, Windows, iOS, Android)\n' + ' --pythonpath Path to the Python interpreter\n' + ' --pythonversion Analyze for a specific version (3.3, 3.4, etc.)\n' + ' --skipunannotated Skip analysis of functions with no type annotations\n' + diff --git a/packages/vscode-pyright/schemas/pyrightconfig.schema.json b/packages/vscode-pyright/schemas/pyrightconfig.schema.json index 6fc64e5167c2..cb6c591eb426 100644 --- a/packages/vscode-pyright/schemas/pyrightconfig.schema.json +++ b/packages/vscode-pyright/schemas/pyrightconfig.schema.json @@ -47,7 +47,7 @@ "examples": [ "Linux" ], - "pattern": "^(Linux|Windows|Darwin|All)$" + "pattern": "^(Linux|Windows|Darwin|iOS|Android|All)$" }, "disableBytesTypePromotions": { "type": "boolean",