Mypy: "Unsupported converter" for completely unanotated function

Created on 10 Jan 2019  路  13Comments  路  Source: python/mypy

A slightly different case with same error message just popped up with mypy==0.650:

import attr


def foo(value):
    return value.split()


@attr.s
class Bar:
    field = attr.ib(default=None, converter=foo)
> mypy test_mypy.py
test_mypy.py:10: error: Unsupported converter, only named functions and types are currently supported
bug false-positive good-first-issue priority-1-normal topic-attrs

Most helpful comment

Having the same issue with lambdas.

All 13 comments

Note that adding at least a single annotation to foo fixed this. It looks like this should be easy to fix.

cc @euresti

Having the same issue with lambdas.

How is possible to skip this warning? It appears even in typed functions and it annoys me.

Someone (you?) will have to update the plugin.

@ilevkivskyi can you demonstrate how I Can add an annotation to suppress this error?

Ah @ilevkivskyi I see you mean this:

import attr

def foo(value) -> str:
    return value.split()

@attr.s
class Bar:
    field = attr.ib(default=None, converter=foo)

@officialcryptomaster Yes.

Seems like similar issue exists with flake8 which does not go away with type annotations... Any idea how I can work around that one other than suppress it?

@officialcryptomaster this sounds like you should report the issue to flake8, unless I'm misunderstanding what you say.

This is also happening with annotated functions that use functools.singledispatch().

Maybe the warning should read "Unsupported converter, only types and named functions with an annotated return type are currently supported" 馃檪

This somehow seems to be broken for attrs 20.3. For

import attr

def foo(value) -> str:
    return value.split()

@attr.s
class Bar:
    field = attr.ib(default=None, converter=foo)

mypy gives me error: Need type annotation for 'field', while it works with attrs 19.3. Not sure if this issue needs to be addressed in mypy or attrs.

I'm pretty sure this last one is because attrs changed the stubs.

Was this page helpful?
0 / 5 - 0 ratings