Skip to content

Commit

Permalink
Fixed bug that results in false negative when a parameter is used wit…
Browse files Browse the repository at this point in the history
…hin a type expression and the parameter's type is a TypeVar or Self. This addresses #9750.
  • Loading branch information
erictraut committed Jan 23, 2025
1 parent 426f294 commit de5d5bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4871,7 +4871,9 @@ export function createTypeEvaluator(
}

if (isTypeVar(type)) {
return true;
if (type.props?.specialForm || type.props?.typeAliasInfo) {
return true;
}
}

// Exempts class types that are created by calling NewType, NamedTuple, etc.
Expand Down
12 changes: 12 additions & 0 deletions packages/pyright-internal/src/tests/samples/annotations1.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,15 @@ class ClassJ:

# This should generate an error because format strings aren't allowed.
x13: f"int"


class A:
def method1(self):
# This should result in an error.
x: self

@classmethod
def method2(cls):
# This should result in an error.
x: cls

2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/typeEvaluator1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ test('FunctionMember2', () => {
test('Annotations1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['annotations1.py']);

TestUtils.validateResults(analysisResults, 19);
TestUtils.validateResults(analysisResults, 21);
});

test('Annotations2', () => {
Expand Down

0 comments on commit de5d5bb

Please sign in to comment.