attrs icon indicating copy to clipboard operation
attrs copied to clipboard

`Unexpected argument` warnings in Pycharm for `@define`-derived syntax

Open sondrelg opened this issue 3 years ago β€’ 10 comments

Thanks for maintaining attrs πŸ™‚ I was hoping to start using the newer syntax in a project, but ran into a tiny issue:

Code sample

import attr


@attr.s
class A:
    a: str
    b: int
    c: bool

    @classmethod
    def from_method(cls, a, b, c):
        return cls(a=a, b=b, c=c)


@attr.define
class B:
    a: str
    b: int
    c: bool

    @classmethod
    def from_method(cls, a, b, c):
        return cls(a=a, b=b, c=c)

What happens

For attrs.define, attrs.frozen, attrs.mutable, etc. all trigger IDE warnings in Pycharm.

image

Do you have any idea what the issue might be here? I tried looking at the stubs Pycharm uses, but wasn't able to find any obvious differences that would explain this.

sondrelg avatar May 02 '22 09:05 sondrelg

I would imagine it's an issue on their end. Does it also happens when you use attrs.define (as opposed to attr)?

Tinche avatar May 02 '22 10:05 Tinche

The issue persists for both import paths, unfortunately

sondrelg avatar May 02 '22 10:05 sondrelg

Please, please, please report this to PyCharm, or upvote a potentially existing bug (I think we already had a similar bug here). They tend to be customer-oriented so this is our best chance.

hynek avatar May 02 '22 13:05 hynek

Before I do, just to eliminate the possibility of long unnecessary waits for several parties: do you not know of any difference between define and attrs decorators that could explain this? There's no dynamic argument recognition based on default properties that Pycharm might be inferring correctly?

If not, I'd be happy to report it there and link it back to this discussion.

sondrelg avatar May 02 '22 13:05 sondrelg

There's https://peps.python.org/pep-0681/, which we do support both for attr.s and define.

Tinche avatar May 02 '22 13:05 Tinche

Yeah it's important to remember that the interference of what an attrs (or dataclass)-decorated class looks like does not come from the type stubs. The type checkers have to implement their own support. PyCharm added direct support quite early, Mypy has a separate plugin.

PEP 681 that Tin mentioned is supposed to fix that, although a lot of that is the lowest common denominator. But it's better than nothing.

hynek avatar May 02 '22 15:05 hynek

Thanks for the quick responses. I'll open an issue in the Pycharm bug tracker when I get a chance and link to it here.

Would it make sense to keep this issue open in the meantime, or would you prefer closing it?

sondrelg avatar May 02 '22 17:05 sondrelg

I guess we can leave one open so people don't open more issues.

Also: @pauleveritt my heart is broken by your lack of love. ;) Pls poke around? πŸ₯ΊπŸΆ

hynek avatar May 02 '22 18:05 hynek

I added a comment to https://youtrack.jetbrains.com/issue/PY-47532/Suuport-new-attrs-aliases, since this ticket seems to be pretty closely related πŸ‘

sondrelg avatar May 02 '22 19:05 sondrelg

@hynek Customer oriented but PyCon hungover. I'll post something in our Slack now.

pauleveritt avatar May 07 '22 11:05 pauleveritt

There's nothing we can do her – let's pray to the Kanban gods.

hynek avatar Aug 11 '22 08:08 hynek