Skip to content

Commit

Permalink
Merge tag 'refs/tags/1.1.371' into merge-1.1.371
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/pyright/package-lock.json
#	packages/pyright/package.json
#	packages/vscode-pyright/package.json
  • Loading branch information
DetachHead committed Jul 10, 2024
2 parents 248ef56 + 8f82d8d commit 0d5ed3c
Show file tree
Hide file tree
Showing 558 changed files with 5,830 additions and 2,631 deletions.
146 changes: 146 additions & 0 deletions build/azuredevops/azure-pipelines-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
trigger:
branches:
include:
- refs/tags/*
resources:
repositories:
- repository: MicroBuildTemplate
type: git
name: 1ESPipelineTemplates/MicroBuildTemplate
ref: refs/tags/release
variables:
- SigningType: 'real'
- TeamName: Pyright
- VSIX_NAME: vscode-pyright.vsix
- ARTIFACT_NAME_VSIX: vsix

extends:
template: azure-pipelines/MicroBuild.1ES.Official.yml@MicroBuildTemplate
parameters:
sdl:
sourceAnalysisPool: VSEngSS-MicroBuild2022-1ES
pool:
name: AzurePipelines-EO
demands:
- ImageOverride -equals 1ESPT-Ubuntu22.04
os: Linux
customBuildTags:
- ES365AIMigrationTooling
stages:
- stage: BuildVsix
jobs:
- job: build
displayName: Build VSIX
timeoutInMinutes: 720
templateContext:
outputs:
- output: pipelineArtifact
displayName: 'publish vsix artifact'
targetPath: build_output
artifactName: $(ARTIFACT_NAME_VSIX)
steps:
- checkout: self
clean: true
submodules: true
fetchTags: true
persistCredentials: True
- task: MicroBuildSigningPlugin@4
inputs:
signType: '$(SignType)'
feedSource: 'https://devdiv.pkgs.visualstudio.com/DefaultCollection/_packaging/MicroBuildToolset/nuget/v3/index.json'
env:
TeamName: '$(TeamName)'
- task: NodeTool@0
displayName: Use Node 18.x
inputs:
versionSpec: 18.x
- task: CmdLine@2
displayName: npm install
inputs:
script: npm run install:all
- task: CmdLine@2
displayName: Package VSIX
inputs:
script: |
npm run package
mv pyright-*.vsix $(VSIX_NAME)
workingDirectory: packages/vscode-pyright
- task: CopyFiles@2
displayName: 'Copy vsix to: build_output'
inputs:
SourceFolder: packages/vscode-pyright
Contents: '*.vsix'
TargetFolder: build_output
- stage: CreateRelease
dependsOn:
- BuildVsix
jobs:
- job: create_release
displayName: Create GitHub Release
steps:
- checkout: none
- download: current
- task: GitHubRelease@1 #https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/github-release-v1?view=azure-pipelines
displayName: 'Create GitHub Release'
inputs:
gitHubConnection: 'Github-Pylance' # The name of the GitHub service connection
repositoryName: 'microsoft/pyright' # The name of your GitHub repository
action: 'create'
isDraft: true
isPreRelease: false
addChangeLog: true
title: 'Published $(Build.SourceBranchName)'
assets: |
$(Pipeline.Workspace)/$(ARTIFACT_NAME_VSIX)/$(VSIX_NAME)
- stage: WaitForValidation
dependsOn:
- CreateRelease
jobs:
- job: wait_for_validation
displayName: Wait for manual validation
pool: server
steps:
- task: ManualValidation@0
timeoutInMinutes: 120 # task times out in 2 hours
inputs:
notifyUsers: 'plseng@microsoft.com,eric@traut.com'
instructions: 'In the next 2 hours please test the latest draft release of Pyright, then Publish the release in GitHub.'
onTimeout: 'resume'

- stage: PublishExtension
dependsOn:
- WaitForValidation
jobs:
- job: publish_extension
displayName: Publish extension to marketplace
steps:
- checkout: none
- task: NodeTool@0
inputs:
versionSpec: 18.x
- task: DownloadGitHubRelease@0
displayName: 'Download VSIX'
inputs:
connection: 'Github-Pylance'
userRepository: 'microsoft/pyright'
defaultVersionType: 'specificTag'
version: $(Build.SourceBranchName)
downloadPath: '$(System.ArtifactsDirectory)'
# https://code.visualstudio.com/api/working-with-extensions/publishing-extension
# Install dependencies and VS Code Extension Manager (vsce >= v2.26.1 needed)
- script: |
npm install -g @vscode/vsce
displayName: 'Install vsce and dependencies'
# https://code.visualstudio.com/api/working-with-extensions/publishing-extension#get-a-personal-access-token
# Publish to Marketplace
# see. stackoverflow.com/collectives/ci-cd/articles/76873787/publish-azure-devops-extensions-using-azure-workload-identity
- task: AzureCLI@2
displayName: 'Publishing with Managed Identity'
inputs:
azureSubscription: PyrightPublishPipelineSecureConnectionWithManagedIdentity
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az rest -u https://app.vssps.visualstudio.com/_apis/profile/profiles/me --resource 499b84ac-1321-427f-aa17-267ca6975798
$aadToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
vsce publish --pat $aadToken --packagePath $(System.ArtifactsDirectory)/$(VSIX_NAME) --noVerify
5 changes: 3 additions & 2 deletions build/azuredevops/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ extends:
- task: CmdLine@2
displayName: npm install
inputs:
script: npm install
script: npm run install:all
- task: CmdLine@2
displayName: Package VSIX
inputs:
script: npm run package
script: |
npm run package
workingDirectory: packages/vscode-pyright
- task: CopyFiles@2
displayName: 'Copy vsix to: build_output'
Expand Down
11 changes: 7 additions & 4 deletions docs/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ Pyright can be run as either a VS Code extension or as a command-line tool. The
| --skipunannotated | Skip type analysis of unannotated functions |
| --stats | Print detailed performance stats |
| -t, --typeshedpath `<DIRECTORY>` | Use typeshed type stubs at this location (3) |
| -v, --venvpath `<DIRECTORY>` | Directory that contains virtual environments (4) |
| --threads <optional N> | Use up to N threads to parallelize type checking (4) |
| -v, --venvpath `<DIRECTORY>` | Directory that contains virtual environments (5) |
| --verbose | Emit verbose diagnostics |
| --verifytypes `<IMPORT>` | 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 (5) |
| -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.
Expand All @@ -34,9 +35,11 @@ Pyright can be run as either a VS Code extension or as a command-line tool. The

(3) Pyright has built-in typeshed type stubs for Python stdlib functionality. To use a different version of typeshed type stubs, specify the directory with this option.

(4) This option is the same as the language server setting `python.venvPath`. It used in conjunction with configuration file, which can refer to different virtual environments by name. For more details, refer to the [configuration](configuration.md) and [import resolution](import-resolution.md#configuring-your-python-environment) documentation. This allows a common config file to be checked in to the project and shared by everyone on the development team without making assumptions about the local paths to the venv directory on each developer’s computer.
(4) This feature is experimental. If thread count is > 1, multiple copies of pyright are executed in parallel to type check files in a project. If no thread count is specified, the thread count is based on the number of available logical processors (if at least 4) or 1 (if less than 4).

(5) When running in watch mode, pyright will reanalyze only those files that have been modified. These “deltas” are typically much faster than the initial analysis, which needs to analyze all files in the source tree.
(5) This option is the same as the language server setting `python.venvPath`. It used in conjunction with configuration file, which can refer to different virtual environments by name. For more details, refer to the [configuration](configuration.md) and [import resolution](import-resolution.md#configuring-your-python-environment) documentation. This allows a common config file to be checked in to the project and shared by everyone on the development team without making assumptions about the local paths to the venv directory on each developer’s computer.

(6) When running in watch mode, pyright will reanalyze only those files that have been modified. These “deltas” are typically much faster than the initial analysis, which needs to analyze all files in the source tree.


# Pyright Exit Codes
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "1.1.370",
"version": "1.1.371",
"command": {
"version": {
"push": false,
Expand Down
4 changes: 2 additions & 2 deletions packages/pyright-internal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/pyright-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pyright-internal",
"displayName": "pyright",
"description": "Type checker for the Python language",
"version": "1.1.370",
"version": "1.1.371",
"license": "MIT",
"private": true,
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export class Binder extends ParseTreeWalker {
const enclosingClass = ParseTreeUtils.getEnclosingClass(node);
if (enclosingClass) {
// Add the implicit "__class__" symbol described in PEP 3135.
this._addImplicitSymbolToCurrentScope('__class__', node, 'class');
this._addImplicitSymbolToCurrentScope('__class__', node, 'type[self]');
}

this._deferBinding(() => {
Expand Down
10 changes: 7 additions & 3 deletions packages/pyright-internal/src/analyzer/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ export function validateConstructorArguments(
inferenceContext: InferenceContext | undefined,
signatureTracker: UniqueSignatureTracker | undefined
): CallResult {
// If this is an unspecialized generic type alias, specialize it now
// using default type argument values.
if (type.typeAliasInfo?.typeParameters && !type.typeAliasInfo.typeArguments) {
const typeAliasTypeVarContext = new TypeVarContext(type.typeAliasInfo.typeVarScopeId);
type = applySolvedTypeVars(type, typeAliasTypeVarContext, { unknownIfNotFound: true }) as ClassType;
}

const metaclassResult = validateMetaclassCall(
evaluator,
errorNode,
Expand Down Expand Up @@ -429,9 +436,6 @@ function validateNewMethod(

const typeVarContext = new TypeVarContext(getTypeVarScopeId(type));
typeVarContext.addSolveForScope(getTypeVarScopeId(newMethodTypeResult.type));
if (type.typeAliasInfo) {
typeVarContext.addSolveForScope(type.typeAliasInfo.typeVarScopeId);
}

const callResult = evaluator.useSpeculativeMode(useSpeculativeModeForArgs ? errorNode : undefined, () => {
return evaluator.validateCallArguments(
Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const enum DeclarationType {
Alias,
}

export type IntrinsicType = 'Any' | 'str' | 'str | None' | 'int' | 'Iterable[str]' | 'class' | 'Dict[str, Any]';
export type IntrinsicType = 'Any' | 'str' | 'str | None' | 'int' | 'Iterable[str]' | 'type[self]' | 'Dict[str, Any]';

export interface DeclarationBase {
// Category of this symbol (function, variable, etc.).
Expand Down
32 changes: 25 additions & 7 deletions packages/pyright-internal/src/analyzer/patternMatching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,17 @@ function narrowTypeBasedOnSequencePattern(
canNarrowTuple = false;
}

if (
isClassInstance(entry.subtype) &&
entry.subtype.tupleTypeArguments &&
entry.subtype.tupleTypeArguments.some((typeArg) => typeArg.isUnbounded)
) {
canNarrowTuple = false;
if (isClassInstance(entry.subtype) && entry.subtype.tupleTypeArguments) {
const unboundedIndex = entry.subtype.tupleTypeArguments.findIndex((typeArg) => typeArg.isUnbounded);

if (unboundedIndex >= 0) {
// If the pattern includes a "star" entry that aligns exactly with
// the corresponding unbounded entry in the tuple, we can narrow
// the tuple type.
if (pattern.starEntryIndex === undefined || pattern.starEntryIndex !== unboundedIndex) {
canNarrowTuple = false;
}
}
}
}

Expand Down Expand Up @@ -1320,9 +1325,13 @@ function getSequencePatternInfo(
(t) => t.isUnbounded || isUnpackedVariadicTypeVar(t.type)
);

let tupleDeterminateEntryCount = typeArgs.length;

// If the tuple contains an indeterminate entry, expand or remove that
// entry to match the length of the pattern if possible.
if (tupleIndeterminateIndex >= 0) {
tupleDeterminateEntryCount--;

while (typeArgs.length < patternEntryCount) {
typeArgs.splice(tupleIndeterminateIndex, 0, typeArgs[tupleIndeterminateIndex]);
}
Expand Down Expand Up @@ -1352,7 +1361,16 @@ function getSequencePatternInfo(
if (typeArgs.length === patternEntryCount) {
let isDefiniteNoMatch = false;
let isPotentialNoMatch = tupleIndeterminateIndex >= 0;
if (patternStarEntryIndex !== undefined && patternEntryCount === 1) {

// If the pattern includes a "star entry" and the tuple includes an
// indeterminate-length entry that aligns to the star entry, we can
// assume it will always match.
if (
patternStarEntryIndex !== undefined &&
tupleIndeterminateIndex >= 0 &&
pattern.entries.length - 1 === tupleDeterminateEntryCount &&
patternStarEntryIndex === tupleIndeterminateIndex
) {
isPotentialNoMatch = false;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/pyright-internal/src/analyzer/sourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { LogTracker, getPathForLogging } from '../common/logTracker';
import { stripFileExtension } from '../common/pathUtils';
import { convertOffsetsToRange, convertTextRangeToRange } from '../common/positionUtils';
import { ServiceKeys } from '../common/serviceKeys';
import { ServiceProvider } from '../common/serviceProvider';
import '../common/serviceProviderExtensions';
import * as StringUtils from '../common/stringUtils';
import { Range, TextRange, getEmptyRange } from '../common/textRange';
import { TextRangeCollection } from '../common/textRangeCollection';
Expand All @@ -46,15 +48,13 @@ import { SourceMapper } from './sourceMapper';
import { SymbolTable } from './symbol';
import { TestWalker } from './testWalker';
import { TypeEvaluator } from './typeEvaluatorTypes';
import '../common/serviceProviderExtensions';
import { ServiceProvider } from '../common/serviceProvider';

// Limit the number of import cycles tracked per source file.
const _maxImportCyclesPerFile = 4;

// Allow files up to 50MB in length, same as VS Code.
// https://github.com/microsoft/vscode/blob/1e750a7514f365585d8dab1a7a82e0938481ea2f/src/vs/editor/common/model/textModel.ts#L194
const _maxSourceFileSize = 50 * 1024 * 1024;
export const maxSourceFileSize = 50 * 1024 * 1024;

interface ResolveImportResult {
imports: ImportResult[];
Expand Down Expand Up @@ -498,10 +498,10 @@ export class SourceFile {
try {
// Check the file's length before attempting to read its full contents.
const fileStat = this.fileSystem.statSync(this._uri);
if (fileStat.size > _maxSourceFileSize) {
if (fileStat.size > maxSourceFileSize) {
this._console.error(
`File length of "${this._uri}" is ${fileStat.size} ` +
`which exceeds the maximum supported file size of ${_maxSourceFileSize}`
`which exceeds the maximum supported file size of ${maxSourceFileSize}`
);
throw new Error('File larger than max');
}
Expand Down
Loading

0 comments on commit 0d5ed3c

Please sign in to comment.