Doesn't understand the attrs `default` and `converter` arguments correctly
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Mypy is complaining about incompatible assignment when it should not, because the default value assigned in the attr.ib() call will be passed to the converter (and be converted). But it seems that mypy do no currently understand that.
attrs docs about order of execution: https://www.attrs.org/en/stable/init.html#order-of-execution
To Reproduce
Code example
from pathlib import Path
import attr
@attr.s
class Options:
path: Path = attr.ib(default='.', converter=Path)
Expected Behavior
It should not trigger errors.
Actual Behavior
Triggers error: 6: error: Incompatible types in assignment (expression has type "str", variable has type "Path")
Your Environment
- Mypy version used: mypy 0.910
- Mypy command-line flags: Nothing special
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.8
- Operating system and version: MacOS catalina
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 provided Python reproducer and the attrs order-of-execution documentation, then trace mypy's handling of attr.ib() defaults and converters. Done means the example no longer reports an incompatible assignment while existing attrs typing behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100