In context, I had the function's return type as List[bytes], and the return statement return sorted(b - a), so even if sorted(b - a) returned List[object], I'd still see a type error when it checks against List[bytes], right?
makes mypy complain about the last line in the example above. This seems reasonable to me. (Similar to the other set operations.) This is also in line with the other container types. For example, we only ordering comparisons between lists of the same type, but for sets we allow any set. This is inconsistent.
Activity
gvanrossum commented on Jan 24, 2018
But if we did that, wouldn't mypy just infer T as object and still allow it?
chadaustin commented on Jan 24, 2018
In context, I had the function's return type as List[bytes], and the return statement return sorted(b - a), so even if sorted(b - a) returned List[object], I'd still see a type error when it checks against List[bytes], right?
gvanrossum commented on Jan 24, 2018
chadaustin commented on Jan 24, 2018
Better a surprising type error (easily diagnosed with reveal_type) than shipping a no-op to production, as I did before submitting this issue. :)
srittau commented on Oct 28, 2018
Changing object to _T in this line:
typeshed/stdlib/3/builtins.pyi
Line 717 in 9ee4582
makes mypy complain about the last line in the example above. This seems reasonable to me. (Similar to the other set operations.) This is also in line with the other container types. For example, we only ordering comparisons between lists of the same type, but for sets we allow any set. This is inconsistent.
set difference strictly: fix python#1840
set difference strictly: fix python#1840
set difference strictly (#3886)