forked from microsoft/pyright
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug in type evaluator where it not properly handling properties…
… within protocol classes.
- Loading branch information
1 parent
094bd03
commit b623cb0
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This sample tests the assignment of protocols that | ||
# include property declarations. | ||
|
||
from typing import Protocol | ||
|
||
class Foo1(Protocol): | ||
@property | ||
def batch_shape(self) -> int: | ||
return 0 | ||
|
||
|
||
class MockFoo1: | ||
def __init__(self, batch_shape: int): | ||
self._batch_shape = batch_shape | ||
|
||
@property | ||
def batch_shape(self) -> int: | ||
return self._batch_shape | ||
|
||
# This should not generate an error. | ||
d: Foo1 = MockFoo1(batch_shape=1) | ||
|
||
|
||
class Foo2(Protocol): | ||
@property | ||
def batch_shape(self) -> int: | ||
return 0 | ||
|
||
|
||
class MockFoo2: | ||
def __init__(self, batch_shape: int): | ||
self._batch_shape = batch_shape | ||
|
||
@property | ||
def batch_shape(self) -> float: | ||
return self._batch_shape | ||
|
||
# This should generate an error because the | ||
# type of the batch_shape property is not compatible. | ||
e: Foo2 = MockFoo2(batch_shape=1) | ||
|