Reputation: 15901
mypy
give no error, but pytype
can't handle this code and rise attribute-error
. How can I fix it?
Code:
# foo/__init__.py
from typing import List
import attr
@attr.s(auto_attribs=True)
class A:
x: List[int] = attr.ib()
@x.default
def bar(self) -> List[int]:
return [1]
Log:
pytype foo
Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `/home/iaro/sample/.pytype'
[1/1] check foo.__init__
FAILED: /home/iaro/sample/.pytype/pyi/foo/__init__.pyi
/home/iaro/.cache/pypoetry/virtualenvs/tmp-eIhQjmCm-py3.7/bin/python -m pytype.single --imports_info /home/iaro/sample/.pytype/imports/foo.__init__.imports --module-name foo.__init__ -V 3.7 -o /home/iaro/sample/.pytype/pyi/foo/__init__.pyi --analyze-annotated --nofail --quick /home/iaro/sample/foo/__init__.py
File "/home/iaro/sample/foo/__init__.py", line 11, in A: No attribute 'default' on List[int] [attribute-error]
For more details, see https://google.github.io/pytype/errors.html#attribute-error.
ninja: build stopped: subcommand failed.
Versions:
attr.__version__
'19.3.0'
mypy --version
mypy 0.770
pytype --version
2020.04.22
P.S. I want to do it without # pytype: disable=attribute-error
in @x.default
line
Upvotes: 0
Views: 803