ruff
38d022f0 - [ty] Patch typeshed mapping key annotations during sync (#25831)

Commit
155 days ago
[ty] Patch typeshed mapping key annotations during sync (#25831) ## Summary Updated our typeshed sync to: - patch `dict.get` and `Mapping.get` to accept `object` keys - patch `dict_keys.isdisjoint` and `dict_items.isdisjoint` to accept `object` - apply the typeshed patches at the end of the sync in a standalone commit The workflow pushes the completed, unpatched sync first, so a patch conflict can be fixed from the unfinished sync branch without rerunning the full workflow. The currently vendored stubs include the patched signatures immediately. Used a typeshed-patching approach similar to mypy, with a directory of patch files that we apply in order. If a patch fails to apply, the final sync job fails while leaving the unpatched sync branch available for manual repair. Closes https://github.com/astral-sh/ty/issues/2374 ## Rationale These methods can safely be called with any key without erroring, so the current annotations are too strict and cause false positives. See https://github.com/python/typeshed/issues/15271 for upstream discussion in typeshed. It's reasonable to want a diagnostic in cases when the `.get()` call is known to return `None`, or the `isdisjoint` call is known to be always true; switching to `object` loses that. In the short term we could provide this via dedicated rule. Longer-term there is discussion upstream about an `Overlapping[...]` annotation form that would allow passing any type that is not disjoint with the annotated type. There are other methods mentioned in that typeshed issue that in principle we might want to patch for similar reasons, but I'm preferring to keep the patch-set smaller and start with just the methods we've seen come up. ## Validation - Added mdtest regression coverage for every `get` overload form accepting `object`. - Ran the focused `call/builtins.md` mdtest. - Ran the full `ty_python_semantic` test suite: 558 passed. - Applied the exact workflow `git apply` command to the current post-docstring, post-format vendored baseline and verified the results byte-for-byte. - Verified that applying the patches a second time fails rather than silently succeeding. - Ran file-scoped `prek` hooks, including GitHub workflow validation. Ecosystem results are mostly the expected false-positive removals, plus some downstream additions where allowing the `.get()` call gives a precise type instead of `Unknown`, causing downstream diagnostics. This change does mean that subclass overrides of `Mapping.get` may now emit Liskov violations if they don't accept `object` -- I think this is an unavoidable part of this change?
Author
Parents
Loading