File tree Expand file tree Collapse file tree 4 files changed +36
-7
lines changed
packages/pyright-internal/src Expand file tree Collapse file tree 4 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -5332,6 +5332,15 @@ export class Checker extends ParseTreeWalker {
5332
5332
overrideFunction = overrideType ;
5333
5333
} else if ( isOverloadedFunction ( overrideType ) ) {
5334
5334
overrideFunction = OverloadedFunctionType . getImplementation ( overrideType ) ;
5335
+ } else if ( isClassInstance ( overrideType ) && ClassType . isPropertyClass ( overrideType ) ) {
5336
+ const fgetSymbol = overrideType . details . fields . get ( 'fget' ) ;
5337
+
5338
+ if ( fgetSymbol ) {
5339
+ const fgetType = this . _evaluator . getDeclaredTypeOfSymbol ( fgetSymbol ) ?. type ;
5340
+ if ( fgetType && isFunction ( fgetType ) ) {
5341
+ overrideFunction = fgetType ;
5342
+ }
5343
+ }
5335
5344
}
5336
5345
5337
5346
if ( ! overrideFunction ?. details . declaration || FunctionType . isOverridden ( overrideFunction ) ) {
@@ -5365,6 +5374,15 @@ export class Checker extends ParseTreeWalker {
5365
5374
overrideFunction = overrideType ;
5366
5375
} else if ( isOverloadedFunction ( overrideType ) ) {
5367
5376
overrideFunction = OverloadedFunctionType . getImplementation ( overrideType ) ;
5377
+ } else if ( isClassInstance ( overrideType ) && ClassType . isPropertyClass ( overrideType ) ) {
5378
+ const fgetSymbol = overrideType . details . fields . get ( 'fget' ) ;
5379
+
5380
+ if ( fgetSymbol ) {
5381
+ const fgetType = this . _evaluator . getDeclaredTypeOfSymbol ( fgetSymbol ) ?. type ;
5382
+ if ( fgetType && isFunction ( fgetType ) ) {
5383
+ overrideFunction = fgetType ;
5384
+ }
5385
+ }
5368
5386
}
5369
5387
5370
5388
if ( ! overrideFunction ?. details . declaration || ! FunctionType . isOverridden ( overrideFunction ) ) {
Original file line number Diff line number Diff line change @@ -20,6 +20,13 @@ def method5(self, x: int | str) -> int | str:
20
20
21
21
22
22
class ClassC (ClassA , ClassB ):
23
+ @property
24
+ @override
25
+ # This should generate an error because prop_a doesn't
26
+ # override anything in its base class.
27
+ def prop_a (self ) -> int :
28
+ raise NotImplementedError
29
+
23
30
@override
24
31
def method1 (self ) -> None :
25
32
pass
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ def __init__(self):
12
12
def method1 (self ):
13
13
pass
14
14
15
+ @property
16
+ def prop_c (self ) -> int :
17
+ return 0
18
+
15
19
16
20
class Child (Base ):
17
21
def __init__ (self ):
@@ -20,3 +24,8 @@ def __init__(self):
20
24
# This should generate an error if reportImplicitOverride is enabled.
21
25
def method1 (self ):
22
26
pass
27
+
28
+ @property
29
+ # This should generate an error if reportImplicitOverride is enabled.
30
+ def prop_c (self ) -> int :
31
+ return 0
Original file line number Diff line number Diff line change @@ -147,12 +147,7 @@ test('Hashability1', () => {
147
147
148 148
test ( 'Override1' , ( ) => {
149
149
const analysisResults = TestUtils . typeAnalyzeSampleFiles ( [ 'override1.py' ] ) ;
150
- TestUtils . validateResults ( analysisResults , 2 ) ;
151
- } ) ;
152
-
153
- test ( 'Override1' , ( ) => {
154
- const analysisResults = TestUtils . typeAnalyzeSampleFiles ( [ 'override1.py' ] ) ;
155
- TestUtils . validateResults ( analysisResults , 2 ) ;
150
+ TestUtils . validateResults ( analysisResults , 3 ) ;
156
151
} ) ;
157
152
158
153
test ( 'Override2' , ( ) => {
@@ -163,7 +158,7 @@ test('Override2', () => {
163
158
164
159
configOptions . diagnosticRuleSet . reportImplicitOverride = 'error' ;
165
160
const analysisResults2 = TestUtils . typeAnalyzeSampleFiles ( [ 'override2.py' ] , configOptions ) ;
166
- TestUtils . validateResults ( analysisResults2 , 1 ) ;
161
+ TestUtils . validateResults ( analysisResults2 , 2 ) ;
167
162
} ) ;
168
163
169
164
test ( 'TypeVarDefault1' , ( ) => {
You can’t perform that action at this time.
0 commit comments