Content-Length: 208519 | pFad | http://github.com/python-attrs/attrs/issues/1435

B6 Mypy issue when using classmethods as converters · Issue #1435 · python-attrs/attrs · GitHub
Skip to content

Mypy issue when using classmethods as converters #1435

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

Open
AdrianSosic opened this issue Jun 2, 2025 · 0 comments
Open

Mypy issue when using classmethods as converters #1435

AdrianSosic opened this issue Jun 2, 2025 · 0 comments

Comments

@AdrianSosic
Copy link

Hi, I just noticed a typing problem when using factory classmethods as converters. The following code works properly with mypy when calling the constructor directly, but causes problems when calling the equivalent factory method. Perhaps some type hints are too strict?

from __future__ import annotations

from attrs import define, field


@define
class LeContainer:
    attr: int

    @classmethod
    def make(cls, a: int) -> LeContainer:
        return LeContainer(a)


@define
class LeClass:
    # x: LeContainer = field(converter=LeContainer)  <-- This works
    x: LeContainer = field(converter=LeContainer.make)  # <-- This makes mypy complain

Error message:

error: Unsupported converter, only named functions, types and lambdas are currently supported  [misc]
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

No branches or pull requests

1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python-attrs/attrs/issues/1435

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy