Skip to content

Commit

Permalink
Fixed a bug that resulted in a false positive when a contravariant Ty…
Browse files Browse the repository at this point in the history
…peVar was used in a return type in a non-method.
  • Loading branch information
erictraut committed Jan 14, 2024
1 parent f35d4f3 commit 7d38c9a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ import {
Type,
TypeBase,
TypeCategory,
TypeVarScopeType,
TypeVarType,
TypedDictEntry,
UnknownType,
Expand Down Expand Up @@ -4736,7 +4737,11 @@ export class Checker extends ParseTreeWalker {
let isContraTypeVar = false;

doForEachSubtype(returnType, (subtype) => {
if (isTypeVar(subtype) && subtype.details.declaredVariance === Variance.Contravariant) {
if (
isTypeVar(subtype) &&
subtype.details.declaredVariance === Variance.Contravariant &&
subtype.scopeType === TypeVarScopeType.Class
) {
isContraTypeVar = true;
}
});
Expand Down

0 comments on commit 7d38c9a

Please sign in to comment.