mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-19 04:07:36 +03:00
Fixed a bug that resulted in a false positive error when using an unpack operator (*
) in a quoted type annotation with versions of Python prior to 3.11.
This commit is contained in:
parent
74d43236f6
commit
0971dc3f12
@ -217,6 +217,7 @@ export class Parser {
|
||||
private _isInFinally = false;
|
||||
private _isParsingTypeAnnotation = false;
|
||||
private _isParsingIndexTrailer = false;
|
||||
private _isParsingQuotedText = false;
|
||||
private _futureImportMap = new Map<string, boolean>();
|
||||
private _importedModules: ModuleImport[] = [];
|
||||
private _containsWildcardImport = false;
|
||||
@ -288,8 +289,10 @@ export class Parser {
|
||||
|
||||
let parseTree: ExpressionNode | FunctionAnnotationNode | undefined;
|
||||
if (parseTextMode === ParseTextMode.VariableAnnotation) {
|
||||
this._isParsingQuotedText = true;
|
||||
parseTree = this._parseTypeAnnotation();
|
||||
} else if (parseTextMode === ParseTextMode.FunctionAnnotation) {
|
||||
this._isParsingQuotedText = true;
|
||||
parseTree = this._parseFunctionTypeAnnotation();
|
||||
} else {
|
||||
const exprListResult = this._parseTestOrStarExpressionList(
|
||||
@ -3524,7 +3527,9 @@ export class Parser {
|
||||
|
||||
if (argType !== ArgumentCategory.Simple) {
|
||||
const unpackAllowed =
|
||||
this._parseOptions.isStubFile || this._getLanguageVersion() >= PythonVersion.V3_11;
|
||||
this._parseOptions.isStubFile ||
|
||||
this._isParsingQuotedText ||
|
||||
this._getLanguageVersion() >= PythonVersion.V3_11;
|
||||
|
||||
if (argType === ArgumentCategory.UnpackedDictionary || !unpackAllowed) {
|
||||
this._addError(Localizer.Diagnostic.unpackedSubscriptIllegal(), argNode);
|
||||
@ -4357,7 +4362,11 @@ export class Parser {
|
||||
if (isUnpack) {
|
||||
if (!allowUnpack) {
|
||||
this._addError(Localizer.Diagnostic.unpackInAnnotation(), startToken);
|
||||
} else if (!this._parseOptions.isStubFile && this._getLanguageVersion() < PythonVersion.V3_11) {
|
||||
} else if (
|
||||
!this._parseOptions.isStubFile &&
|
||||
!this._isParsingQuotedText &&
|
||||
this._getLanguageVersion() < PythonVersion.V3_11
|
||||
) {
|
||||
this._addError(Localizer.Diagnostic.unpackedSubscriptIllegal(), startToken);
|
||||
}
|
||||
}
|
||||
|
@ -54,3 +54,6 @@ def func11(*v11: *tuple[int, ...]):
|
||||
def func12(*v11: *tuple[int, int]):
|
||||
pass
|
||||
|
||||
def func13(v12: "tuple[str, *tuple[int, ...], str]"):
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user