mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Fixed a bug that results in a false positive error when a decorator is applied to a property. This addresses #7740. (#7913)
This commit is contained in:
parent
506f2c14dd
commit
6c7470d51e
@ -313,7 +313,8 @@ function addGetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
|
||||
hasDeclaredType: true,
|
||||
});
|
||||
|
||||
const objType = fget.details.parameters.length > 0 ? fget.details.parameters[0].type : AnyType.create();
|
||||
const objType =
|
||||
fget.details.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fget, 0) : AnyType.create();
|
||||
|
||||
FunctionType.addParameter(getFunction2, {
|
||||
category: ParameterCategory.Simple,
|
||||
@ -358,7 +359,8 @@ function addSetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
|
||||
hasDeclaredType: true,
|
||||
});
|
||||
|
||||
let objType = fset.details.parameters.length > 0 ? fset.details.parameters[0].type : AnyType.create();
|
||||
let objType =
|
||||
fset.details.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fset, 0) : AnyType.create();
|
||||
if (isTypeVar(objType) && objType.details.isSynthesizedSelf) {
|
||||
objType = evaluator.makeTopLevelTypeVarsConcrete(objType);
|
||||
}
|
||||
@ -412,7 +414,8 @@ function addDelMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
|
||||
delFunction.details.typeVarScopeId = getTypeVarScopeId(fdel);
|
||||
delFunction.details.deprecatedMessage = fdel.details.deprecatedMessage;
|
||||
|
||||
let objType = fdel.details.parameters.length > 0 ? fdel.details.parameters[0].type : AnyType.create();
|
||||
let objType =
|
||||
fdel.details.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fdel, 0) : AnyType.create();
|
||||
|
||||
if (isTypeVar(objType) && objType.details.isSynthesizedSelf) {
|
||||
objType = evaluator.makeTopLevelTypeVarsConcrete(objType);
|
||||
|
@ -1,10 +1,11 @@
|
||||
# This sample tests the case where a @property decorator is applied to
|
||||
# a method that has been previously decorated.
|
||||
|
||||
from typing import ParamSpec, TypeVar, Callable
|
||||
from typing import Concatenate, ParamSpec, Protocol, TypeVar, Callable
|
||||
|
||||
P = ParamSpec("P")
|
||||
R = TypeVar("R")
|
||||
S = TypeVar("S", bound="HasAttr")
|
||||
|
||||
|
||||
def deco1(func: Callable[P, R]) -> Callable[P, R]: ...
|
||||
@ -19,3 +20,25 @@ class ClassA:
|
||||
|
||||
a = ClassA()
|
||||
reveal_type(a.prop, expected_text="int")
|
||||
|
||||
|
||||
class HasAttr(Protocol):
|
||||
my_attr: str
|
||||
|
||||
|
||||
def decorate(
|
||||
func: Callable[Concatenate[S, P], R]
|
||||
) -> Callable[Concatenate[S, P], R]: ...
|
||||
|
||||
|
||||
class ClassB:
|
||||
my_attr: str
|
||||
|
||||
@property
|
||||
@decorate
|
||||
def prop(self) -> int:
|
||||
return 1
|
||||
|
||||
|
||||
b = ClassB()
|
||||
reveal_type(b.prop, expected_text="int")
|
||||
|
Loading…
Reference in New Issue
Block a user