Open
Description
I'd like mypy to recognize attr.s decorated classes by "indirect" means.
To understand what I mean, consider the examples in the snippet below:
import attr
# example 1 (works with mypy)
@attr.s(auto_attribs=True, frozen=True)
class DirectlyDecorated:
name: str
d = DirectlyDecorated('foo') # no mypy error
# --- end example 1
# example 2 (does not work with mypy)
my_decorator = attr.s(auto_attribs=True, frozen=True)
@my_decorator
class IndirectlyDecorated:
name: str
i = IndirectlyDecorated('bar') # error: Too many arguments for "IndirectlyDecorated"
# --- end example 2
# example 3 (does not work with mypy)
class MyMeta(type):
def __new__(cls, name, bases, dct):
newcls = super().__new__(cls, name, bases, dct)
newcls = my_decorator(newcls)
return newcls
class MetaDecorated(metaclass=MyMeta):
name: str
m = MetaDecorated('baz') # error: Too many arguments for "MetaDecorated"
# --- end example 3
Running git master version of mypy as of today, with no arguments, I get:
snippet.py:25: error: Too many arguments for "IndirectlyDecorated"
snippet.py:43: error: Too many arguments for "MetaDecorated"
So, example 1 works as expected. Examples 2 and 3 do not work:
The same happens when using kw_only=True
(that is example1 with kw_only=True works, but neither examples 2 nor 3 work with kw_only=True
). In that case, the error reported is, of course,
snippet.py:25: error: Unexpected keyword argument "name" for "IndirectlyDecorated"
snippet.py:43: error: Unexpected keyword argument "name" for "MetaDecorated"
I'd like mypy to recognize the above cases so that example 2 and 3 work (with both kw_only=True
and kw_only=False
)
Thank you