Method override in subclass is not detected, is this by design? #3057
-
Given the following code: class A:
def foo(self):
self.bar()
def bar(self):
raise Exception()
class B(A):
def bar(self):
print("baz")
b = B()
b.foo()
print("finished") I get an error that the last line is unreachable (not quite sure if it's Pyright or Pylance generating this error in VS code). I figure this is because the I could of course ask them to make it an |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, this is expected behavior. The inferred return type for You have the following options to work around this:
|
Beta Was this translation helpful? Give feedback.
Yes, this is expected behavior. The inferred return type for
A.bar
isNoReturn
.You have the following options to work around this:
NotImplementedError
rather thanException
; this is the common (and recommended) pattern in most Python code, so pyright special-cases itNone
return type annotation toA.bar
so inference doesn't need to be used