Type checking unexpectedly passing when misusing `default` and `converter`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start by running the Python 2/3 reproducer and checking the reported MyPy diagnostics for A, especially the y attribute using default=None and _convert_int. Trace whether the missing error belongs to attrs' generated typing information or to MyPy/Typeshed, and consider the issue done when the ownership and a regression check for this case are established.
Written by the indexing model from the issue text.
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?
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/attrs
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
python-attrs/attrs#1543 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1532 ·
All issues in python-attrs/attrs
Similar issues
-
bug confirmed issue
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
open-webui/open-webui#30750 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 90/100