My instinct is to try it the stricter way and relax it if we ever get a real user complaint about it, but happy to go along with whatever others think is best
I'd like to provide such a complaint. In ty, we would like to infer precise key-type specializations (unions of string literals) of dict_keys and dict_items for closed TypedDicts, where all possible keys are known. We have real user requests for this, because it allows iterating over dict keys/items and passing the keys along to a function that expects a limited set of literals.
But doing this causes false positives with isdisjoint, because the following valid code will now error:
classTD(TypedDict, closed=True):
x: intdefcheck(td: TD) ->None:
# Both operations are safe at runtime but will report invalid-argument-type:td.keys().isdisjoint(["other"])
td.items().isdisjoint([("other", 1)])
This is really a sub-issue of #15271, the same category of issue as #6597.
Arguably the code in the OP could be considered an error (or at least linted against), since the calls will always return True. Perhaps a better example of the false positive is this:
Activity
carljm commented on Jun 10, 2026
Arguably the code in the OP could be considered an error (or at least linted against), since the calls will always return True. Perhaps a better example of the false positive is this:
Using an Overlapping[...] annotation here would allow this valid usage, but still error on the known-true call in the OP.