Skip to content

Add support for attr.converters.default_if_none #6136

Open
@bellorap

Description

@bellorap

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions