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

Merge 1.1.381 #676

Merged
merged 28 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0d92942
Fixed bug that results in incorrect type narrowing for sequence patte…
erictraut Sep 11, 2024
a0ecfe2
Pull Pylance with Pyright 1.1.380 (#8969)
StellaHuang95 Sep 11, 2024
dd3ba0a
Fixed recent regression that results in a false positive error when a…
erictraut Sep 12, 2024
10b372d
Fixed a bug that results in incorrect evaluation of a variable in a d…
erictraut Sep 13, 2024
c3580db
Fixed a bug that results in incorrect narrowing of types for `TypeIs`…
erictraut Sep 13, 2024
edaeab2
Mutate sourceFile imports list whenever it changes (#8986)
dcolascione Sep 13, 2024
9ea762f
Improved comment for clarity.
erictraut Sep 13, 2024
d3821e9
Made adjustments to `TypeForm` behaviors based on feedback on draft P…
erictraut Sep 13, 2024
171f052
Fixed recent regression that results in incorrect type narrowing for …
erictraut Sep 14, 2024
63c7c30
Expanded `reportUnnecessaryIsinstance` check to report cases where an…
erictraut Sep 14, 2024
7eb358a
Fixed bug that results in incorrect reporting of the Python version i…
erictraut Sep 14, 2024
ecdab93
Improved error message for type violation in assignment statement whe…
erictraut Sep 15, 2024
6c28123
Fixed bug that results in incorrect code flow involving a call to a `…
erictraut Sep 15, 2024
fb5cc8c
Fixed bug that results in a spurious "symbol refers to itself" error …
erictraut Sep 15, 2024
c799d9e
Fixed bug that can theoretically result in spurious errors when evalu…
erictraut Sep 16, 2024
f3ed499
Fixed bug that results in incorrect type narrowing when `TypeIs` inte…
erictraut Sep 16, 2024
e94fa86
Allow venvPath to be set in settings.json (#9007)
rchiodo Sep 16, 2024
a203953
Fixed bug that results in a confusing error message extension referen…
erictraut Sep 16, 2024
1eb1bc7
Fixed a bug that results in a false positive type error and confusing…
erictraut Sep 16, 2024
e353c9d
Put back logic of recreating the background analysis token on every s…
rchiodo Sep 17, 2024
c20e613
Fixed a bug that results in spurious "variable not allowed in type ex…
erictraut Sep 17, 2024
ea18695
Add new vscode signing (#8977) (#9019)
bschnurr Sep 17, 2024
06ab7a8
Update Unicode range tables to match Unicode 16.0 (#9020)
debonte Sep 17, 2024
a56a4ec
Published 1.1.381
erictraut Sep 17, 2024
f66f05c
Merge tag 'refs/tags/1.1.381' into merge-1.1.381
DetachHead Sep 18, 2024
958af90
fix type errors from merge
DetachHead Sep 18, 2024
03e7502
fix browser-basedpyright. accidentally dropped this when merging upst…
DetachHead Sep 18, 2024
d640a50
add a dev build script for browser-basedpyright
DetachHead Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 61 additions & 10 deletions build/azuredevops/azure-pipelines-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extends:
codeql:
compiled:
enabled: false
justificationForDisabling: 'Running a scan on the Pyright-Build'
justificationForDisabling: 'Running a scan on the Pyright-Build azure-pipelines.yml'
sourceAnalysisPool: VSEngSS-MicroBuild2022-1ES
pool:
pool:
Expand Down Expand Up @@ -82,6 +82,59 @@ extends:
SourceFolder: packages/vscode-pyright
Contents: '*.vsix'
TargetFolder: build_output

- script: |
npm install -g @vscode/vsce
displayName: 'Install vsce and dependencies'

- script: npx vsce generate-manifest -i $(VSIX_NAME) -o extension.manifest
displayName: 'Generate extension manifest'
workingDirectory: packages/vscode-pyright

- task: NuGetToolInstaller@1
displayName: 'Install NuGet'

- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '$(Build.SourcesDirectory)/packages/vscode-pyright/packages.config'
restoreDirectory: '$(Build.SourcesDirectory)/packages/vscode-pyright/packages'

- task: MSBuild@1
displayName: 'Sign binaries'
inputs:
solution: 'packages/vscode-pyright/sign.proj'
msbuildArguments: '/verbosity:diagnostic /p:SignType=real'

- task: PowerShell@2
displayName: 'Compare extension.manifest and extension.signature.p7s'
inputs:
targetType: 'inline'
script: |
$manifestPath = "$(Build.SourcesDirectory)\packages\vscode-pyright\extension.manifest"
$signaturePath = "$(Build.SourcesDirectory)\packages\vscode-pyright\extension.signature.p7s"
$compareResult = Compare-Object (Get-Content $manifestPath) (Get-Content $signaturePath)
if ($compareResult -eq $null) {
Write-Error "Files are identical. Failing the build."
exit 1
} else {
Write-Output "Files are different."
}

- task: CopyFiles@2
displayName: 'Copy extension.manifest'
inputs:
SourceFolder: 'packages/vscode-pyright'
Contents: 'extension.manifest'
TargetFolder: build_output

- task: CopyFiles@2
displayName: 'Copy extension.signature.p7s'
inputs:
SourceFolder: 'packages/vscode-pyright'
Contents: 'extension.signature.p7s'
TargetFolder: build_output

- stage: CreateRelease
dependsOn:
- BuildVsix
Expand Down Expand Up @@ -129,14 +182,12 @@ extends:
- task: NodeTool@0
inputs:
versionSpec: 18.x
- task: DownloadGitHubRelease@0
displayName: 'Download VSIX'
- task: DownloadPipelineArtifact@2
displayName: 'Download Artifacts from Validation Job'
inputs:
connection: 'Github-Pylance'
userRepository: 'microsoft/pyright'
defaultVersionType: 'specificTag'
version: $(Build.SourceBranchName)
downloadPath: '$(System.ArtifactsDirectory)'
buildType: 'current'
artifactName: '$(ARTIFACT_NAME_VSIX)'
targetPath: '$(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: |
Expand All @@ -145,13 +196,13 @@ extends:
# 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
# az rest -u https://app.vssps.visualstudio.com/_apis/profile/profiles/me --resource 499b84ac-1321-427f-aa17-267ca6975798
- 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
vsce publish --pat $aadToken --packagePath $(System.ArtifactsDirectory)/$(VSIX_NAME) --noVerify --manifestPath $(System.ArtifactsDirectory)/extension.manifest --signaturePath $(System.ArtifactsDirectory)/extension.signature.p7s
19 changes: 10 additions & 9 deletions build/generateUnicodeTables.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def getSurrogateRanges(chars: list[Character]) -> list[CharacterRange]:
def writeRangeTable(writer: TextIOWrapper, category: str, chars: list[Character]):
chars = [ch for ch in chars if ch.category == category]

writer.write("\n")
writer.write(f"export const unicode{category}: UnicodeRangeTable = [\n")

consecutiveRangeStartChar: Character | None = None
Expand All @@ -126,13 +127,13 @@ def writeRangeTable(writer: TextIOWrapper, category: str, chars: list[Character]

if i + 1 >= len(chars) or chars[i + 1].code != char.code + 1:
if consecutiveRangeStartChar.code == char.code:
writer.write(f" 0x{consecutiveRangeStartChar.code:04X},\n")
writer.write(f" 0x{consecutiveRangeStartChar.code:04x},\n")
else:
writer.write(f" [0x{consecutiveRangeStartChar.code:04X}, 0x{char.code:04X}],\n")
writer.write(f" [0x{consecutiveRangeStartChar.code:04x}, 0x{char.code:04x}],\n")

consecutiveRangeStartChar = None

writer.write("];\n\n")
writer.write("];\n")


# Write out a table of all characters within the specified category using their UTF-16
Expand All @@ -146,6 +147,7 @@ def writeSurrogateRangeTable(
if len(surrogateRanges) == 0:
return

writer.write("\n")
writer.write(
f"export const unicode{category}Surrogate: UnicodeSurrogateRangeTable = {{\n"
)
Expand All @@ -160,21 +162,21 @@ def writeSurrogateRangeTable(
previousCharRange = None

if not previousCharRange:
writer.write(f" 0x{charRange.start.highSurrogate:04X}: [\n")
writer.write(f" 0x{charRange.start.highSurrogate:04x}: [\n")
previousCharRange = charRange

if charRange.start.lowSurrogate == charRange.end.lowSurrogate:
writer.write(f" 0x{charRange.start.lowSurrogate:04X}, // 0x{charRange.start.code:04X}\n")
writer.write(f" 0x{charRange.start.lowSurrogate:04x}, // 0x{charRange.start.code:04X}\n")
else:
writer.write(
f" [0x{charRange.start.lowSurrogate:04X}, 0x{charRange.end.lowSurrogate:04X}], // 0x{charRange.start.code:04X}..0x{charRange.end.code:04X}\n"
f" [0x{charRange.start.lowSurrogate:04x}, 0x{charRange.end.lowSurrogate:04x}], // 0x{charRange.start.code:04X}..0x{charRange.end.code:04X}\n"
)

writer.write(" ],\n")
writer.write("};\n\n")
writer.write("};\n")


unicodeVersion = "15.1" if len(sys.argv) <= 1 else sys.argv[1]
unicodeVersion = "16.0" if len(sys.argv) <= 1 else sys.argv[1]
path = downloadUnicodeData(unicodeVersion)
chars = parseFile(path)
surrogateRanges = getSurrogateRanges(chars)
Expand All @@ -196,7 +198,6 @@ def writeSurrogateRangeTable(
export type UnicodeRange = [number, number] | number;
export type UnicodeRangeTable = UnicodeRange[];
export type UnicodeSurrogateRangeTable = {{ [surrogate: number]: UnicodeRange[] }};

"""
)

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ The following settings allow more fine grained control over the **typeCheckingMo

- <a name="reportCallInDefaultInitializer"></a> **reportCallInDefaultInitializer** [boolean or string, optional]: Generate or suppress diagnostics for function calls, list expressions, set expressions, or dictionary expressions within a default value initialization expression. Such calls can mask expensive operations that are performed at module initialization time.

- <a name="reportUnnecessaryIsInstance"></a> **reportUnnecessaryIsInstance** [boolean or string, optional]: Generate or suppress diagnostics for `isinstance` or `issubclass` calls where the result is statically determined to be always true. Such calls are often indicative of a programming error.
- <a name="reportUnnecessaryIsInstance"></a> **reportUnnecessaryIsInstance** [boolean or string, optional]: Generate or suppress diagnostics for `isinstance` or `issubclass` calls where the result is statically determined to be always true or always false. Such calls are often indicative of a programming error.

- <a name="reportUnnecessaryCast"></a> **reportUnnecessaryCast** [boolean or string, optional]: Generate or suppress diagnostics for `cast` calls that are statically determined to be unnecessary. Such calls are sometimes indicative of a programming error.

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.380",
"version": "1.1.381",
"command": {
"version": {
"push": false,
Expand Down
1 change: 1 addition & 0 deletions packages/browser-pyright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"scripts": {
"build": "webpack --mode production --progress",
"build:dev": "webpack --mode development --progress",
"clean": "shx rm -rf ./dist ./out LICENSE.txt",
"prepack": "npm run clean && shx cp ../../LICENSE.txt . && npm run build",
"webpack": "webpack --mode development --progress"
Expand Down
11 changes: 8 additions & 3 deletions packages/browser-pyright/src/browserWorkersHost.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Transferable,
WorkersHost,
MessageSourceSink,
Worker,
MessagePort,
MessageChannel,
shallowReplace,
Expand All @@ -22,7 +22,7 @@ export class BrowserWorkersHost implements WorkersHost {
return this._parentPort ? new BrowserMessagePort(this._parentPort) : null;
}

createWorker(initialData?: any): MessageSourceSink {
createWorker(initialData?: any): Worker {
const channel = new globalThis.MessageChannel();
self.postMessage(
{
Expand All @@ -46,7 +46,7 @@ export class BrowserWorkersHost implements WorkersHost {
}
}

class BrowserMessagePort implements MessagePort {
class BrowserMessagePort implements MessagePort, Worker {
constructor(private _delegate: globalThis.MessagePort) {}
unwrap() {
return this._delegate;
Expand All @@ -73,6 +73,11 @@ class BrowserMessagePort implements MessagePort {
close() {
this._delegate.close();
}
terminate = () => {
console.warn('Worker.terminate was called. TODO: figure out what to do');
this._delegate.close(); // this?
return Promise.resolve(0);
};
}

function unwrapForSend(value: any): any {
Expand Down
3 changes: 3 additions & 0 deletions packages/browser-pyright/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module.exports = async (_, { mode }) => {
entry: {
pyright: './src/worker.ts',
},
optimization: {
minimize: mode === 'production',
},
output: {
filename: '[name].worker.js',
path: outPath,
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.380",
"version": "1.1.381",
"license": "MIT",
"private": true,
"files": [
Expand Down
3 changes: 3 additions & 0 deletions packages/pyright-internal/src/analyzer/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface AnalysisResults {
configParseErrors: string[];
elapsedTime: number;
error?: Error | undefined;
reason: 'analysis' | 'tracking';
}

export interface RequiringAnalysisCount {
Expand Down Expand Up @@ -76,6 +77,7 @@ export function analyzeProgram(
fatalErrorOccurred: false,
configParseErrors: [],
elapsedTime,
reason: 'analysis',
});
}
} catch (e: any) {
Expand All @@ -95,6 +97,7 @@ export function analyzeProgram(
configParseErrors: [],
elapsedTime: 0,
error: debug.getSerializableError(e),
reason: 'analysis',
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class BackgroundAnalysisProgram {
this._disableChecker,
serviceId
);
this._backgroundAnalysis?.setProgramView(this._program);
}

get configOptions() {
Expand Down Expand Up @@ -155,7 +156,7 @@ export class BackgroundAnalysisProgram {

startAnalysis(token: CancellationToken): boolean {
if (this._backgroundAnalysis) {
this._backgroundAnalysis.startAnalysis(this, token);
this._backgroundAnalysis.startAnalysis(token);
return false;
}

Expand Down Expand Up @@ -233,6 +234,7 @@ export class BackgroundAnalysisProgram {
this._disposed = true;
this._program.dispose();
this._backgroundAnalysis?.shutdown();
this._backgroundAnalysis?.dispose();
}

enterEditMode() {
Expand Down Expand Up @@ -272,6 +274,7 @@ export class BackgroundAnalysisProgram {
fatalErrorOccurred: false,
configParseErrors: [],
elapsedTime: 0,
reason: 'tracking',
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/analyzer/cacheManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import type { HeapInfo } from 'v8';
import { AnalysisRequest } from '../backgroundAnalysisBase';
import { BackgroundRequest } from '../backgroundAnalysisBase';
import { ConsoleInterface } from '../common/console';
import { fail } from '../common/debug';
import { getHeapStatistics, getSystemMemoryInfo } from '../common/memUtils';
Expand Down Expand Up @@ -51,7 +51,7 @@ export class CacheManager {
}
}

handleCachedUsageBufferMessage(msg: AnalysisRequest) {
handleCachedUsageBufferMessage(msg: BackgroundRequest) {
if (msg.requestType === 'cacheUsageBuffer') {
const index = parseInt(msg.data || '0');
const buffer = msg.sharedUsageBuffer;
Expand Down
35 changes: 25 additions & 10 deletions packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3868,20 +3868,35 @@ export class Checker extends ParseTreeWalker {
node
);

if (isNever(narrowedTypeNegative)) {
const narrowedTypePositive = narrowTypeForInstanceOrSubclass(
this._evaluator,
arg0Type,
classTypeList,
isInstanceCheck,
/* isTypeIsCheck */ false,
/* isPositiveTest */ true,
node
);

const isAlwaysTrue = isNever(narrowedTypeNegative);
const isNeverTrue = isNever(narrowedTypePositive);

if (isAlwaysTrue || isNeverTrue) {
const classType = combineTypes(classTypeList.map((t) => convertToInstance(t)));
const messageTemplate = isAlwaysTrue
? isInstanceCheck
? LocMessage.unnecessaryIsInstanceAlways()
: LocMessage.unnecessaryIsSubclassAlways()
: isInstanceCheck
? LocMessage.unnecessaryIsInstanceNever()
: LocMessage.unnecessaryIsSubclassNever();

this._evaluator.addDiagnostic(
DiagnosticRule.reportUnnecessaryIsInstance,
isInstanceCheck
? LocMessage.unnecessaryIsInstanceAlways().format({
testType: this._evaluator.printType(arg0Type),
classType: this._evaluator.printType(classType),
})
: LocMessage.unnecessaryIsSubclassAlways().format({
testType: this._evaluator.printType(arg0Type),
classType: this._evaluator.printType(classType),
}),
messageTemplate.format({
testType: this._evaluator.printType(arg0Type),
classType: this._evaluator.printType(classType),
}),
node
);
}
Expand Down
Loading
Loading