-
I believe it's a bug, but PR template suggests posting here first What's wrong with
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The fact that you're using You have declared that the variable You could make your program type correct by adding an assert: def apply_filter(self):
assert isinstance(self.filters, RegExFilter)
print(self.filters.pattern) |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
The fact that you're using
__slots__
here has nothing to do with the type violation you're seeing. You can completely remove__slots__
from your example, and you'll see the same behavior.You have declared that the variable
filters
in the classAbstract
must be of typeFilter
. In the classImpl
, you are assigning a value to this variable that indeed conforms to the typeFilter
(sinceRegExFilter
is a subclass ofFilter
), so that is not a type violation. However, you're later relying on the fact thatAbstract.filters
is aRegExFilter
rather than aFilter
. That's a type violation, and pyright is correct to highlight it. There is nothing that preventsImpl.filters
from being overwritten by a…