Skip to content

Commit

Permalink
Fixed a bug that led to a false negative when a type annotation conta…
Browse files Browse the repository at this point in the history
…ins a stringified type on the LHS of an index expression. This addresses #5811. (#5816)

Co-authored-by: Eric Traut <[email protected]>
  • Loading branch information
erictraut and msfterictraut authored Aug 26, 2023
1 parent e77b921 commit 1a34728
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6245,14 +6245,11 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | EvaluatorFlags.IndexBaseDefaults);

// If this is meant to be a type and the base expression is a string expression,
// emit an error because this will generate a runtime exception in Python versions
// less than 3.10.
// emit an error because this is an illegal annotation form and will generate a
// runtime exception.
if (flags & EvaluatorFlags.ExpectingInstantiableType) {
if (node.baseExpression.nodeType === ParseNodeType.StringList) {
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
if (!fileInfo.isStubFile && fileInfo.executionEnvironment.pythonVersion < PythonVersion.V3_10) {
addError(Localizer.Diagnostic.stringNotSubscriptable(), node.baseExpression);
}
addError(Localizer.Diagnostic.stringNotSubscriptable(), node.baseExpression);
}
}

Expand Down

0 comments on commit 1a34728

Please sign in to comment.