Bug with filter
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
from typing import Optional
from typing import Sequence
from more_itertools import first
class A:
def some_method(self):
pass
def f(inp: Sequence[A]) -> Optional[A]:
return first(filter(lambda a: a.some_method(), inp), None)
Output
test.py:13: error: Item "None" of "Optional[A]" has no attribute "some_method"
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 by reproducing the diagnostic with the Python snippet in the issue, then trace how mypy infers the callback and result types for filter and more_itertools.first. The fix is complete when this example no longer reports that the value may be None, while genuinely optional values remain checked correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100