Open
Description
I was playing around with type annotations and Attrs, and I think I may have found an issue.
Given the following Python 2/3 script:
from __future__ import absolute_import
from pprint import pprint as pp
import attr
def _convert_int(val):
# type: (int) -> int
if val <= 0:
return -1
return val
@attr.s
class A(object):
x = attr.ib(default=0, converter=_convert_int, type=int)
y = attr.ib(default=None, converter=_convert_int, type=int) # `default` is incompatible with our declared `type`
def main():
# type: () -> None
a1 = A(5, 5) # correct: type checks
pp(a1)
a2 = A(5, None) # correct: doesn't type check
pp(a2)
a3 = A(5) # incorrect: type checks but shouldn't!
pp(a3)
if __name__ == '__main__':
main()
I'd expect MyPy to complain about the relationship between default
and converter
for y
. Nevertheless, I'm getting:
Which is one error less than expected.
Should I perhaps report this to MyPy or Typeshed as well/instead?