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

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

Closed
Redoubts opened this issue Oct 12, 2023 · 6 comments
Labels
bug mypy got something wrong topic-attrs

Comments

@Redoubts
Copy link

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
@Redoubts Redoubts added the bug mypy got something wrong label Oct 12, 2023
@Ranfir
Copy link

Ranfir commented Oct 12, 2023

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

@awerchniak
Copy link

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)

@jp-larose
Copy link

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.

@ikonst
Copy link
Contributor

ikonst commented Oct 24, 2023

This was fixed in #15983.

@Redoubts
Copy link
Author

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

@AlexWaygood
Copy link
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
Labels
bug mypy got something wrong topic-attrs
Projects
None yet
Development

No branches or pull requests

6 participants