You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just cause I am reading through issues: is the root problem not using converters.optional? Or alternatively, adding a None check in the local validator?
frompprintimportpprintasppimportattrfromattrimportconvertersdef_convert_int(val):
# type: (int) -> intifval<=0:
return-1returnval@attr.sclassA(object):
x=attr.ib(default=0, converter=_convert_int, type=int)
y=attr.ib(default=None, converter=converters.optional(_convert_int), type=int) # `default` is incompatible with our declared `type`defmain():
# type: () -> Nonea1=A(5, 5) # correct: type checkspp(a1)
a2=A(5, None) # correct: doesn't type checkpp(a2)
a3=A(5) # incorrect: type checks but shouldn't!pp(a3)
if__name__=='__main__':
main()
@stevetarver In my example, I want y to not allow None.
In any case, I believe this goes beyond being an issue with converters only, since I would have expected the following excerpt to fail at class definition:
/Users/apizarro/tmp/test.py:10: error: Argument 1 to "Foo" has incompatible type "None"; expected "int"
Found 1 error in 1 file (checked 1 source file)
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:
I'd expect MyPy to complain about the relationship between
default
andconverter
fory
. Nevertheless, I'm getting:Which is one error less than expected.
Should I perhaps report this to MyPy or Typeshed as well/instead?
The text was updated successfully, but these errors were encountered: