Skip to content

Method override in subclass is not detected, is this by design? #3057

Answered by erictraut
Hugovdberg asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, this is expected behavior. The inferred return type for A.bar is NoReturn.

You have the following options to work around this:

  1. Make it an abstractmethod
  2. Raise a NotImplementedError rather than Exception; this is the common (and recommended) pattern in most Python code, so pyright special-cases it
  3. Add an explicit None return type annotation to A.bar so inference doesn't need to be used

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Hugovdberg
Comment options

Answer selected by Hugovdberg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants