stubgen infers function returns None if it passes or raise NotImplementedError
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
-
Are you reporting a bug, or opening a feature request?
Reporting a bug, although I'm not sure what the intended behavior is. -
Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
class A:
def f(self):
raise NotImplementedError
def g(self):
"""A is not an abstract base class"""
return "Hello World"
class B(A):
def f(self):
return 5
class C:
def f(self):
pass
- What is the actual behavior/output?
stubgen output:
class A:
def f(self) -> None: ...
def g(self): ...
class B(A):
def f(self): ...
class C:
def f(self) -> None: ...
- What is the behavior/output you expect?
class A:
def f(self): ...
def g(self): ...
class B(A):
def f(self): ...
class C:
def f(self): ...
This is because I would like to write code like
def h(a: A):
return a.f()
h(B())
without typing errors. In realistic use cases, A has multiple subclasses.
- What are the versions of mypy and Python you are using?
Python 3.7.7
mypy 0.782
Do you see the same issue after installing mypy from Git master?
Yes
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the stubgen behavior shown in the issue and reproduce it using the A, B, and C example. Trace how stubgen infers return annotations for methods that pass or raise NotImplementedError, then verify the generated stubs no longer add None in those cases while preserving the shown subclass methods.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100