8000 Fixed recent regression that resulted in attribution of a type var to… · nejch/scip-python@6792731 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 6792731

Browse files
committed
Fixed recent regression that resulted in attribution of a type var to the wrong scope when it was used in an __init__ method of a class with a class decorator.
1 parent 06c4ef1 commit 6792731

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

packages/pyright-internal/src/analyzer/typeEvaluator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14991,6 +14991,9 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
1499114991

1499214992
const effectiveMetaclass = computeEffectiveMetaclass(classType, node.name);
1499314993

14994+
// Clear the "partially constructed" flag.
14995+
classType.details.flags &= ~ClassTypeFlags.PartiallyEvaluated;
14996+
1499414997
// Now determine the decorated type of the class.
1499514998
let decoratedType: Type = classType;
1499614999
let foundUnknown = false;
@@ -15037,9 +15040,6 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
1503715040
applyDataClassClassBehaviorOverrides(evaluatorInterface, classType, initSubclassArgs);
1503815041
}
1503915042

15040-
// Clear the "partially constructed" flag.
15041-
classType.details.flags &= ~ClassTypeFlags.PartiallyEvaluated;
15042-
1504315043
// Run any class hooks that depend on this class.
1504415044
runClassTypeHooks(classType);
1504515045

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This sample tests the case where a class decorator needs to evaluate
2+
# the type of __init__ prior to the class being fully evaluated.
3+
4+
from typing import Any, Callable, Generic, TypeVar
5+
6+
T = TypeVar("T")
7+
FuncType = Callable[..., Any]
8+
FT = TypeVar("FT", bound=FuncType)
9+
10+
11+
def decorate() -> Callable[[FT], FT]:
12+
...
13+
14+
15+
@decorate()
16+
class ValueDecorated(Generic[T]):
17+
def __init__(self, value: T) -> None:
18+
self._value: T = value
19+
20+
def __call__(self) -> T:
21+
return self._value

packages/pyright-internal/src/tests/typeEvaluator3.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,12 @@ test('Decorator6', () => {
12541254
TestUtils.validateResults(analysisResults, 0);
12551255
});
12561256

1257+
test('Decorator7', () => {
1258+
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['decorator7.py']);
1259+
1260+
TestUtils.validateResults(analysisResults, 0);
1261+
});
1262+
12571263
test('DataclassTransform1', () => {
12581264
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['dataclassTransform1.py']);
12591265

0 commit comments

Comments
 (0)
0