Add support for attr.converters.default_if_none
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I have the following:
@attr.s(auto_attribs=True)
class Foo:
bars: List[Bar] = attr.ib(
default=attr.Factory(list),
converter=default_if_none(default=attr.Factory(list)),
)
I'm running mypy via pre-commit and getting:
error: Unsupported converter, only named functions and types are currently supported
I have the following in my .pre-commit-config.yaml:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.650
hooks:
- id: mypy
additional_dependencies:
- attrs>=18.2.0
(Without the additional_dependencies part I also get error: Module 'attr.converters' has no attribute 'default_if_none')
Could the issue be that there's special handling for optional here but not for default_if_none?
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 in mypy/plugins/attrs.py at the existing special handling for optional converters linked in the issue, then reproduce the reported snippet with mypy through the pre-commit configuration. Trace how attr.converters.default_if_none is validated and determine the expected typing behavior; done means the converter is accepted without the reported errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100