mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Added support for @abc.abstractproperty decorator.
This commit is contained in:
parent
7be19b6a52
commit
a6bf2c0e59
@ -2347,7 +2347,8 @@ export class TypeAnalyzer extends ParseTreeWalker {
|
||||
return inputFunctionType;
|
||||
}
|
||||
|
||||
case 'property': {
|
||||
case 'property':
|
||||
case 'abstractproperty': {
|
||||
if (inputFunctionType.category === TypeCategory.Function) {
|
||||
// Allocate a property only during the first analysis pass.
|
||||
// Otherwise the analysis won't converge if there are setters
|
||||
|
33
server/src/tests/samples/properties2.py
Normal file
33
server/src/tests/samples/properties2.py
Normal file
@ -0,0 +1,33 @@
|
||||
# This sample tests handling of the @abc.abstractpropery decorator.
|
||||
|
||||
import abc
|
||||
|
||||
def requires_int(x: int):
|
||||
pass
|
||||
|
||||
|
||||
class Foo(abc.ABC):
|
||||
@abc.abstractproperty
|
||||
def x(self) -> int:
|
||||
raise NotImplementedError
|
||||
|
||||
@x.setter
|
||||
def x(self, value: int):
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractproperty
|
||||
def y(self) -> float:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
a = Foo()
|
||||
requires_int(a.x)
|
||||
|
||||
a.x = 3
|
||||
|
||||
# This should generate an error because a.y is not an int
|
||||
requires_int(a.y)
|
||||
|
||||
# This should generate an error because the assigned type
|
||||
# isn't compatible with the setter.
|
||||
a.x = 4.5
|
@ -283,6 +283,12 @@ test('Properties1', () => {
|
||||
validateResults(analysisResults, 5);
|
||||
});
|
||||
|
||||
test('Properties2', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['properties2.py']);
|
||||
|
||||
validateResults(analysisResults, 2);
|
||||
});
|
||||
|
||||
test('Operators1', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['operators1.py']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user