[PylanceBot] Pull Pylance with Pyright 1.1.365 (#8016)

* pull-pylance-with-pyright-1.1.365-9280185292

* Update package.nls.ko.json typo

Fix typo

---------

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Rich Chiodo <rchiodo@users.noreply.github.com>
This commit is contained in:
PylanceBot 2024-05-29 09:49:41 -07:00 committed by GitHub
parent 66101ee0c5
commit 2e397e9a0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 107 additions and 23 deletions

View File

@ -884,14 +884,18 @@ export class ImportResolver {
return '.'.repeat(moduleDescriptor.leadingDots) + moduleDescriptor.nameParts.join('.');
}
protected getParentImportResolutionRoot(sourceFileUri: Uri, executionRoot: Uri | undefined) {
if (executionRoot && !executionRoot.isEmpty()) {
return this.fileSystem.realCasePath(executionRoot);
protected getParentImportResolutionRoot(sourceFileUri: Uri, executionRoot: Uri | undefined): Uri {
if (!this._isDefaultWorkspace(executionRoot)) {
return executionRoot!;
}
return sourceFileUri.getDirectory();
}
private _isDefaultWorkspace(uri: Uri | undefined) {
return !uri || uri.isEmpty() || Uri.isDefaultWorkspace(uri);
}
private _resolveImportStrict(
importName: string,
sourceFileUri: Uri,
@ -2790,7 +2794,7 @@ export class ImportResolver {
return (
current &&
!current.isEmpty() &&
(current.isChild(root) || (current.equals(root) && (!execEnv.root || execEnv.root.isEmpty())))
(current.isChild(root) || (current.equals(root) && this._isDefaultWorkspace(execEnv.root)))
);
}
}

View File

@ -87,6 +87,8 @@ export class FileUri extends BaseUri {
originalString: string | undefined,
isCaseSensitive: boolean
): FileUri {
filePath = isDiskPathRoot(filePath) ? ensureTrailingDirectorySeparator(filePath) : filePath;
const key = FileUri._createKey(filePath, query, fragment);
return new FileUri(key, filePath, query, fragment, originalString, isCaseSensitive);
}

View File

@ -270,4 +270,20 @@ export namespace Uri {
export function is(thing: any): thing is Uri {
return !!thing && typeof thing._key === 'string';
}
export function isEmpty(uri: Uri | undefined): boolean {
return !uri || uri.isEmpty();
}
export function equals(a: Uri | undefined, b: Uri | undefined): boolean {
if (a === b) {
return true;
}
return a?.equals(b) ?? false;
}
export function isDefaultWorkspace(uri: Uri) {
return uri.fileName.includes(DefaultWorkspaceRootComponent);
}
}

View File

@ -154,6 +154,8 @@
"ellipsisContext": "„...“ se v tomto kontextu nepovoluje",
"ellipsisSecondArg": "„...“ je povoleno pouze jako druhý ze dvou argumentů",
"enumClassOverride": "Třída výčtu {name} je konečná a nemůže být podtřídou",
"enumMemberDelete": "Člen výčtu {name} se nedá odstranit.",
"enumMemberSet": "Člen výčtu {name} se nedá přiřadit.",
"exceptionGroupIncompatible": "Syntaxe skupiny výjimek (except*) vyžaduje Python 3.11 nebo novější",
"exceptionTypeIncorrect": "„{type}“ se neodvozuje od BaseException",
"exceptionTypeNotClass": "{type} není platná třída výjimky",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "\"...\" ist in diesem Kontext nicht zulässig.",
"ellipsisSecondArg": "\"...\" ist nur als zweites von zwei Argumenten zulässig.",
"enumClassOverride": "Die Enumerationsklasse \"{name}\" ist final und kann nicht in eine Unterklasse aufgenommen werden.",
"enumMemberDelete": "Das Enumerationselement \"{name}\" kann nicht gelöscht werden.",
"enumMemberSet": "Das Enumerationselement \"{name}\" kann nicht zugewiesen werden.",
"exceptionGroupIncompatible": "Die Ausnahmegruppensyntax (\"except*\") erfordert Python 3.11 oder höher.",
"exceptionTypeIncorrect": "\"{type}\" ist nicht von BaseException abgeleitet.",
"exceptionTypeNotClass": "\"{type}\" ist keine gültige Ausnahmeklasse.",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "\"...\" no está permitido en este contexto",
"ellipsisSecondArg": "\"...\" está permitido sólo como el segundo de dos argumentos",
"enumClassOverride": "La clase Enum \"{name}\" es final y no puede ser subclasificada",
"enumMemberDelete": "No se puede eliminar el miembro de enumeración \"{name}\"",
"enumMemberSet": "No se puede asignar el miembro de enumeración \"{name}\"",
"exceptionGroupIncompatible": "La sintaxis de grupo de excepciones (\"except*\") requiere Python 3.11 o posterior.",
"exceptionTypeIncorrect": "\"{type}\" no se deriva de BaseException",
"exceptionTypeNotClass": "\"{type}\" no es una clase de excepción válida",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "« ... » nest pas autorisé dans ce contexte",
"ellipsisSecondArg": "« ... » nest autorisé quen tant que second des deux arguments",
"enumClassOverride": "La classe Enum « {name} » est finale et ne peut pas être sous-classée",
"enumMemberDelete": "Le membre enum « {name} » ne peut pas être supprimé",
"enumMemberSet": "Le membre enum « {name} » ne peut pas être affecté",
"exceptionGroupIncompatible": "La syntaxe du groupe dexceptions (« except* ») nécessite Python 3.11 ou version ultérieure",
"exceptionTypeIncorrect": "\"{type}\" ne dérive pas de BaseException",
"exceptionTypeNotClass": "« {type} » nest pas une classe dexception valide",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "\"...\" non è consentito in questo contesto",
"ellipsisSecondArg": "\"...\" è consentito solo come secondo di due argomenti",
"enumClassOverride": "La classe di enumerazione \"{name}\" è finale e non può essere sottoclassata",
"enumMemberDelete": "Non è possibile eliminare il membro di enumerazione \"{name}\"",
"enumMemberSet": "Non è possibile assegnare il membro di enumerazione \"{name}\"",
"exceptionGroupIncompatible": "La sintassi del gruppo di eccezioni (\"except*\") richiede Python 3.11 o versione successiva",
"exceptionTypeIncorrect": "\"{type}\" non deriva da BaseException",
"exceptionTypeNotClass": "\"{type}\" non è una classe di eccezione valida",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "\"...\" はこのコンテキストでは許可されていません",
"ellipsisSecondArg": "\"...\" は2 つの引数の 2 番目の引数としてのみ使用できます",
"enumClassOverride": "列挙型クラス \"{name}\" は最終的なクラスであり、サブクラス化できません",
"enumMemberDelete": "列挙型メンバー \"{name}\" を削除できません",
"enumMemberSet": "列挙型メンバー \"{name}\" を割り当てることはできません",
"exceptionGroupIncompatible": "例外グループの構文 (\"except*\") には Python 3.11 以降が必要です",
"exceptionTypeIncorrect": "\"{type}\" は BaseException から派生していません",
"exceptionTypeNotClass": "\"{type}\" は有効な例外クラスではありません",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "\"...\"는 이 컨텍스트에서는 허용되지 않습니다.",
"ellipsisSecondArg": "\"...\"는 두 인수 중 두 번째 인수로만 허용됩니다.",
"enumClassOverride": "열거형 클래스 \"{name}\"은(는) 최종 클래스이며 서브클래스할 수 없습니다.",
"enumMemberDelete": "열거형 멤버 \"{name}\"을(를) 삭제할 수 없음",
"enumMemberSet": "열거형 멤버 \"{name}\"을(를) 할당할 수 없음",
"exceptionGroupIncompatible": "예외 그룹 구문(\"except*\")에는 Python 3.11 이상이 필요합니다.",
"exceptionTypeIncorrect": "{type}’은 BaseException에서 파생되지 않습니다.",
"exceptionTypeNotClass": "\"{type}\"은(는) 올바른 예외 클래스가 아닙니다.",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "Wartość „...” jest niedozwolona w tym kontekście",
"ellipsisSecondArg": "Wartość „...” jest dozwolona tylko jako drugi z dwóch argumentów",
"enumClassOverride": "Klasa wyliczenia „{name}” jest ostateczna i nie można jej podzielić na podklasy",
"enumMemberDelete": "Nie można usunąć składowej wyliczenia \"{name}\"",
"enumMemberSet": "Nie można przypisać składowej wyliczenia „{name}”",
"exceptionGroupIncompatible": "Składnia grupy wyjątków („except*”) wymaga języka Python w wersji 3.11 lub nowszej",
"exceptionTypeIncorrect": "Typ „{type}” nie pochodzi od parametru BaseException",
"exceptionTypeNotClass": "Typ „{type}” nie jest prawidłową klasą wyjątku",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "\"...\" não é permitido neste contexto",
"ellipsisSecondArg": "\"...\" é permitido apenas como o segundo de dois argumentos",
"enumClassOverride": "A classe Enum \"{name}\" é final e não pode ser subclasse",
"enumMemberDelete": "O membro enumerado \"{name}\" não pode ser excluído",
"enumMemberSet": "O membro enumerado \"{name}\" não pode ser atribuído",
"exceptionGroupIncompatible": "A sintaxe do grupo de exceção (\"exceto*\") requer o Python 3.11 ou mais recente",
"exceptionTypeIncorrect": "\"{type}\" não deriva de BaseException",
"exceptionTypeNotClass": "\"{type}\" não é uma classe de exceção válida",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "[Y4jK3][นั้\"...\" ïs ñøt ælløwëð ïñ thïs çøñtëxtẤğ倪İЂҰक्र्तिृまนั้ढूँ]",
"ellipsisSecondArg": "[pvXJA][นั้\"...\" ïs ælløwëð øñlÿ æs thë sëçøñð øf twø ærgµmëñtsẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्นั้ढूँ]",
"enumClassOverride": "[2JsL1][นั้Ëñµm çlæss \"{ñæmë}\" ïs fïñæl æñð çæññøt þë sµþçlæssëðẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्นั้ढूँ]",
"enumMemberDelete": "[5wmRY][นั้Ëñµm mëmþër \"{ñæmë}\" çæññøt þë ðëlëtëðẤğ倪İЂҰक्र्तिृまẤนั้ढूँ]",
"enumMemberSet": "[mBLro][นั้Ëñµm mëmþër \"{ñæmë}\" çæññøt þë æssïgñëðẤğ倪İЂҰक्र्तिृまẤğนั้ढूँ]",
"exceptionGroupIncompatible": "[d0SLP][นั้Ëxçëptïøñ grøµp sÿñtæx (\"ëxçëpt*\") rëqµïrës Pÿthøñ 3.11 ør ñëwërẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृนั้ढूँ]",
"exceptionTypeIncorrect": "[G7AZt][นั้\"{tÿpë}\" ðøës ñøt ðërïvë frøm ßæsëËxçëptïøñẤğ倪İЂҰक्र्तिृまẤğ倪นั้ढूँ]",
"exceptionTypeNotClass": "[v1FmY][นั้\"{tÿpë}\" ïs ñøt æ vælïð ëxçëptïøñ çlæssẤğ倪İЂҰक्र्तिृまẤğนั้ढूँ]",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "\"...\" не допускается в данном контексте",
"ellipsisSecondArg": "\"...\" разрешается только в качестве второго из двух аргументов",
"enumClassOverride": "Перечислимый класс \"{name}\" является окончательным и не может иметь производных классов",
"enumMemberDelete": "Не удается удалить элемент перечисления \"{name}\"",
"enumMemberSet": "Не удается назначить элемент перечисления \"{name}\"",
"exceptionGroupIncompatible": "Синтаксис группы исключений (\"except*\") можно использовать в Python версии не ранее 3.11",
"exceptionTypeIncorrect": "\"{type}\" не является производным от BaseException",
"exceptionTypeNotClass": "\"{type}\" не является допустимым классом исключений",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "\"...\" kullanımına bu bağlamda izin verilmiyor",
"ellipsisSecondArg": "\"...\" yalnızca iki bağımsız değişkenin ikincisi olarak kullanılabilir",
"enumClassOverride": "\"{name}\" sabit listesi sınıfı final niteliğinde ve alt sınıf olamaz",
"enumMemberDelete": "Sabit liste üyesi \"{name}\" silinemiyor",
"enumMemberSet": "Sabit liste üyesi \"{name}\" atanamıyor",
"exceptionGroupIncompatible": "Özel durum grubu söz dizimi (\"except*\") için Python 3.11 veya daha yeni bir sürümü gerekiyor",
"exceptionTypeIncorrect": "\"{type}\", BaseException türevi değil",
"exceptionTypeNotClass": "\"{type}\" geçerli bir özel durum sınıfı değil",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "不允许在此上下文中使用 \"...\"",
"ellipsisSecondArg": "仅允许 \"...\" 作为两个参数中的第二个参数",
"enumClassOverride": "枚举类“{name}”是最终类,不能为子类",
"enumMemberDelete": "无法删除枚举成员“{name}”",
"enumMemberSet": "无法分配枚举成员“{name}”",
"exceptionGroupIncompatible": "异常组语法 (\"except*\") 需要 Python 3.11 或更高版本",
"exceptionTypeIncorrect": "\"{type}\" 不是派生自 BaseException",
"exceptionTypeNotClass": "“{type}”不是有效的异常类",

View File

@ -154,6 +154,8 @@
"ellipsisContext": "此內容中不允許 \"...\"",
"ellipsisSecondArg": "\"...\" 只允許做為兩個引數的第二個",
"enumClassOverride": "列舉類別 \"{name}\" 為 Final且不能設為子類別",
"enumMemberDelete": "無法刪除列舉成員 \"{name}\"",
"enumMemberSet": "無法指派列舉成員 \"{name}\"",
"exceptionGroupIncompatible": "例外群組語法 (\"except*\") 需要 Python 3.11 或更新版本",
"exceptionTypeIncorrect": "\"{type}\" 不是衍生自 BaseException",
"exceptionTypeNotClass": "\"{type}\" 不是有效的例外類別",

View File

@ -689,6 +689,24 @@ describe('Import tests that can run with or without a true venv', () => {
});
assert(!importResult.isImportFound);
});
test('default workspace importing side by side file', () => {
const files = [
{
path: combinePaths('/', 'src', 'a', 'b', 'file1.py'),
content: 'import file2',
},
{
path: combinePaths('/', 'src', 'a', 'b', 'file2.py'),
content: 'def f(): pass',
},
];
const importResult = getImportResult(files, ['file2'], (config) => {
config.projectRoot = Uri.defaultWorkspace({ isCaseSensitive: () => true });
});
assert(importResult.isImportFound);
});
});
if (usingTrueVenv()) {

View File

@ -691,7 +691,7 @@ test('getWildcardRoot with root', () => {
test('getWildcardRoot with drive letter', () => {
const p = getWildcardRoot(Uri.parse('file:///c:/', caseDetector), '.');
assert.equal(p.toString(), 'file:///c%3A');
assert.equal(p.toString(), 'file:///c%3A/');
});
function resolvePaths(uri: string, ...paths: string[]) {
@ -792,7 +792,7 @@ test('getRootLength2', () => {
});
test('getRootLength3', () => {
assert.equal(getUriRootLength('c:'), 2);
assert.equal(getUriRootLength('c:'), 3);
});
test('getRootLength4', () => {
@ -800,7 +800,7 @@ test('getRootLength4', () => {
});
test('getRootLength5', () => {
assert.equal(getUriRootLength('c:/'), 2);
assert.equal(getUriRootLength('c:/'), 3);
});
test('getRootLength6', () => {
@ -969,3 +969,13 @@ test('constant uri test', () => {
assert(!uri1.equals(uri2));
assert(uri1.equals(uri1));
});
test('root test', () => {
const uri1 = UriEx.file('C:\\');
const uri2 = UriEx.file('C:');
const uri3 = UriEx.file('/');
assert.strictEqual(uri1.getFilePath(), normalizeSlashes('c:/'));
assert.strictEqual(uri2.getFilePath(), normalizeSlashes('c:/'));
assert.strictEqual(uri3.getFilePath(), normalizeSlashes('/'));
});

View File

@ -170,7 +170,7 @@ export class WorkspaceFactory {
applyPythonPath(workspace: Workspace, newPythonPath: Uri | undefined): Uri | undefined {
// See if were allowed to apply the new python path
if (workspace.pythonPathKind === WorkspacePythonPathKind.Mutable && newPythonPath) {
if (workspace.pythonPathKind === WorkspacePythonPathKind.Mutable && !Uri.isEmpty(newPythonPath)) {
const originalPythonPath = workspace.pythonPath;
workspace.pythonPath = newPythonPath;
@ -184,7 +184,7 @@ export class WorkspaceFactory {
}
// If the python path has changed, we may need to move the immutable files to the correct workspace.
if (originalPythonPath && !newPythonPath.equals(originalPythonPath) && workspaceInMap) {
if (originalPythonPath && !Uri.equals(newPythonPath, originalPythonPath) && workspaceInMap) {
// Potentially move immutable files from one workspace to another.
this._moveImmutableFilesToCorrectWorkspace(originalPythonPath, workspaceInMap);
}
@ -347,7 +347,7 @@ export class WorkspaceFactory {
// this workspace.
const oldPathFiles = mutableWorkspace.service.getOpenFiles().filter((f) => this._isPythonPathImmutable(f));
const exitingWorkspaceWithSamePath = this.items().find(
(w) => w.pythonPath === mutableWorkspace.pythonPath && w !== mutableWorkspace
(w) => Uri.equals(w.pythonPath, mutableWorkspace.pythonPath) && w !== mutableWorkspace
);
const newPathFiles =
exitingWorkspaceWithSamePath?.service.getOpenFiles().filter((f) => this._isPythonPathImmutable(f)) ?? [];
@ -434,7 +434,7 @@ export class WorkspaceFactory {
private _getDefaultWorkspaceKey(pythonPath: Uri | undefined) {
return `${this._defaultWorkspacePath}:${
pythonPath !== undefined ? pythonPath : WorkspacePythonPathKind.Mutable
!Uri.isEmpty(pythonPath) ? pythonPath : WorkspacePythonPathKind.Mutable
}`;
}
@ -460,8 +460,8 @@ export class WorkspaceFactory {
await bestInstance.isInitialized.promise;
// If this best instance doesn't match the pythonPath, then we need to create a new one.
if (pythonPath !== undefined && !bestInstance.pythonPath?.equals(pythonPath)) {
bestInstance = this._createImmutableCopy(bestInstance, pythonPath);
if (!Uri.isEmpty(pythonPath) && !bestInstance.pythonPath?.equals(pythonPath)) {
bestInstance = this._createImmutableCopy(bestInstance, pythonPath!);
}
return bestInstance;
@ -472,8 +472,8 @@ export class WorkspaceFactory {
let bestInstance = this._getBestWorkspaceForFile(uri, pythonPath);
// If this best instance doesn't match the pythonPath, then we need to create a new one.
if (pythonPath !== undefined && !bestInstance.pythonPath?.equals(pythonPath)) {
bestInstance = this._createImmutableCopy(bestInstance, pythonPath);
if (!Uri.isEmpty(pythonPath) && !bestInstance.pythonPath?.equals(pythonPath)) {
bestInstance = this._createImmutableCopy(bestInstance, pythonPath!);
}
return bestInstance;
@ -528,7 +528,6 @@ export class WorkspaceFactory {
// 5. If none of the above works, then it matches the default workspace.
// First find the workspaces that are tracking the file
const regularWorkspaces = this.getNonDefaultWorkspaces(WellKnownWorkspaceKinds.Regular);
const trackingWorkspaces = this.items()
.filter((w) => w.service.isTracked(uri))
.filter(isNormalWorkspace);
@ -536,11 +535,18 @@ export class WorkspaceFactory {
// Then find the best in all of those that actually matches the pythonPath.
bestInstance = this._getBestRegularWorkspace(trackingWorkspaces, pythonPath);
const regularWorkspaces = this.getNonDefaultWorkspaces(WellKnownWorkspaceKinds.Regular);
// If it's not in a tracked workspace, see if we only have regular workspaces with the same
// length root path
// length root path (basically, the same workspace with just different python paths)
if (
bestInstance === undefined &&
regularWorkspaces.every((w) => w.rootUri.getPathLength() === regularWorkspaces[0].rootUri.getPathLength())
regularWorkspaces.every(
(w) =>
w.rootUri.scheme === regularWorkspaces[0].rootUri.scheme &&
(w.rootUri.scheme === uri.scheme || uri.isUntitled()) &&
w.rootUri.equals(regularWorkspaces[0].rootUri)
)
) {
bestInstance = this._getBestRegularWorkspace(regularWorkspaces, pythonPath);
}
@ -550,7 +556,7 @@ export class WorkspaceFactory {
if (bestInstance === undefined || !bestInstance.pythonPath?.equals(pythonPath)) {
bestInstance =
this._getBestRegularWorkspace(
regularWorkspaces.filter((w) => w.service.hasSourceFile(uri)),
regularWorkspaces.filter((w) => w.service.hasSourceFile(uri) && w.rootUri.scheme === uri.scheme),
pythonPath
) || bestInstance;
}
@ -573,7 +579,7 @@ export class WorkspaceFactory {
undefined,
this._defaultWorkspacePath,
pythonPath,
pythonPath !== undefined ? WorkspacePythonPathKind.Immutable : WorkspacePythonPathKind.Mutable,
!Uri.isEmpty(pythonPath) ? WorkspacePythonPathKind.Immutable : WorkspacePythonPathKind.Mutable,
[WellKnownWorkspaceKinds.Default]
);
}
@ -592,7 +598,7 @@ export class WorkspaceFactory {
return previousPath;
}, Uri.empty());
return workspaces.find((w) => w.rootUri === longestPath)!;
return workspaces.find((w) => w.rootUri.equals(longestPath))!;
}
private _getBestRegularWorkspace(workspaces: NormalWorkspace[], pythonPath?: Uri): NormalWorkspace | undefined {
@ -606,8 +612,8 @@ export class WorkspaceFactory {
}
// If there's any that match the python path, take the one with the longest path from those.
if (pythonPath !== undefined) {
const matchingWorkspaces = workspaces.filter((w) => w.pythonPath === pythonPath);
if (!Uri.isEmpty(pythonPath)) {
const matchingWorkspaces = workspaces.filter((w) => Uri.equals(w.pythonPath, pythonPath));
if (matchingWorkspaces.length > 0) {
return this._getLongestPathWorkspace(matchingWorkspaces);
}