Skip to content

Argument 1 to "fields" has incompatible type "type[AttrsInstance]"; expected an attrs class #16254

Closed

Description

@Redoubts

Bug Report

mypy is reporting that a type[attrs.AttrsInstance] is not a valid argument to attrs.fields

To Reproduce

from __future__ import annotations

import attrs


@attrs.define
class X:
    x: int


attrs.fields(X) # fine


def func(klass: type[attrs.AttrsInstance]) -> None:
    fields = attrs.fields(klass) # error
    print(fields)


func(X) # fine

Expected Behavior

% mypy x.py
Success: no issues found in 1 source file

Actual Behavior

% mypy x.py
x.py:15: error: Argument 1 to "fields" has incompatible type "type[AttrsInstance]"; expected an attrs class [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.6
  • Mypy command-line flags: (w/ or w/o --no-incremental)
  • Mypy configuration options from mypy.ini (and other config files): default
  • Python version used: 3.10

Activity

  1. Ranfir commented on Oct 12, 2023

    @Ranfir

    I'm also seeing this in 1.6, but not 1.5.1.

  2. awerchniak commented on Oct 19, 2023

    @awerchniak

    I started seeing this when my mypy version jumped from 1.5.1 -> 1.6.1. No difference in my source code or attrs version. Code to reproduce:

    import attr
    
    @attr.s(frozen=True)
    class MyClass(object):
        @classmethod
        def fields(cls):
            return attr.fields(cls)

    we can then see:

    $ .venv/bin/mypy test.py
    exp.py:7: error: Argument 1 to "fields" has incompatible type "type[MyClass]"; expected an attrs class  [misc]
                return attr.fields(cls)
                       ^~~~~~~~~~~~~~~~
    Found 1 error in 1 file (checked 1 source file)
  3. jp-larose commented on Oct 24, 2023

    @jp-larose

    I'm also seeing this in 1.6, but not 1.5.1.

    I am too. However, I tested with the latest from master, and it seems to be fixed 🤞. So I would expect the fix to be included in the next release.

  4. ikonst commented on Oct 24, 2023

    @ikonst
    Contributor

    This was fixed in #15983.

  5. Redoubts commented on Oct 24, 2023

    @Redoubts
    Author

    Do you know if we will get a 1.6.2 cut with this fix?

  6. AlexWaygood commented on Oct 24, 2023

    @AlexWaygood
    Member

    Do you know if we will get a 1.6.2 cut with this fix?

    Probably not; mypy 1.7 is expected soon, I believe. But @hauntsaninja has been managing patch releases for mypy 1.6, so it'll be up to him to decide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions