Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug, typing] MyPy doesn't like attrs.converters #930

Closed
henryiii opened this issue Mar 11, 2022 · 5 comments · Fixed by #931
Closed

[bug, typing] MyPy doesn't like attrs.converters #930

henryiii opened this issue Mar 11, 2022 · 5 comments · Fixed by #931

Comments

@henryiii
Copy link

In MyPy, using attrs.converters gives:

error: Module has no attribute "converters"  [attr-defined]

Adding an import attrs.converters (not needed at runtime) gives:

error: Module has no attribute "optional"

I think part of the problem is the __init__.pyi isn't synced with __init__.py for importing submodules. Not sure why the star import isn't working inside converters.py, though.

@hynek
Copy link
Member

hynek commented Mar 14, 2022

Ugh, looks like our import tests in typing_examples are NOPs.

Each symbol has to be explicitly "re-exported". We've missed filters too.

#931 should fix it.

@henryiii
Copy link
Author

Fantastic, thanks!

I think * imports don't need to be explicitly reexported inside .pyi files, but they do in .py files.

@hynek
Copy link
Member

hynek commented Mar 14, 2022

I mean then your bug wouldn't have happened? :) And yes, the fixed examples triggered the error too.

I'm somewhat OK with being explicit, but in this case it's very annoying. :-/

@danjac
Copy link

danjac commented Jul 3, 2022

I'm seeing the same issue with mypy 0.961 and attrs 21.4.0:

import attrs

@attrs.define(kw_only=True)
class Item:
    length: int | None = attrs.field(
        converter=attrs.converters.optional(
            attrs.converters.pipe(float, int),
        ),
        default=None,
    )

Running in mypy, getting these (possibly related?) errors:

Unsupported converter, only named functions and types are currently supported

error: Module has no attribute "converters" [attr-defined]

@hynek
Copy link
Member

hynek commented Jul 5, 2022

Yes, sorry there hasn't been a release since this has been fixed yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants