Repository navigation
Short-circuit isTypeVarSame subtype checks - #11681
Bill Schnurr (bschnurr) wants to merge 7 commits into
Conversation
|
/benchmark |
|
🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR. |
This comment has been minimized.
This comment has been minimized.
|
Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. |
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
This comment has been minimized.
This comment has been minimized.
72e74f2 to
2901d5f
Compare
|
Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. |
This comment has been minimized.
This comment has been minimized.
2901d5f to
ce7460c
Compare
|
Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. |
This comment has been minimized.
This comment has been minimized.
|
/benchmark |
Fix allSubtypes callback handling and delegate union traversal directly to Array.every. Use it in isTypeVarSame to stop the subtype scan at the first incompatibility instead of invoking no-op callbacks for the remainder. Add direct allSubtypes and someSubtypes coverage.
ce7460c to
c49ce2f
Compare
|
Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Result: Summary: Verification could not run because no trusted `microsoft/pyright` sandbox image was configured and local execution was unauthorized. The PR adds focused coverage for union short-circuiting and non-union callbacks in `allSubtypes` and `someSubtypes`. No meaningful test execution occurred, so the verdict is **could-not-verify**. Test runs: 1 not run
|
This comment has been minimized.
This comment has been minimized.
| sourceNode === source && targetNode === target ? targetNode : undefined; | ||
| } | ||
|
|
||
| test('AllSubtypes', () => { |
There was a problem hiding this comment.
Issue · Please address or respond
Move both new tests above the existing file-scoped helper section. Appending tests after createFunction, createClass, and replacePair violates docs/pylancewiki/review/tests-helper-placement.md, which requires helpers at the end of their scope.
| return classType; | ||
| } | ||
|
|
||
| function createUnion(...subtypes: UnionableType[]) { |
There was a problem hiding this comment.
Issue · Please address or respond
Declare the rest parameter as ...subtypes: readonly UnionableType[]. The helper only reads this array and passes its elements individually downstream, so the mutable parameter violates docs/pylancewiki/review/readonly-by-default.md without a demonstrated mutability requirement.
|
Result: Verification detailsVerification: Isolated verification observed failures that were not classified as caused by this PR: Dependency and test discovery. Summary: Targeted Jest runs passed all 50 selected tests, including both PR-added helper tests and existing TypeVar/union regressions. Offline dependency installation and the internal TypeScript build also passed. Discovery failed only because the container snapshot lacks Git metadata. Hosted validation and mypy_primer were not reproduced, so verification is partial. Test runs: 4 passed, 1 failed
❌
|
|
/benchmark |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
|
Reviewed commit: Result: 🔴 Verification detailsVerification: Automated verification is best effort. The PR author remains responsible for testing. Summary: [unavailable] Container verification could not start and local execution was not authorized for this PR HEAD: C:\Users\rchiodo\AppData\Local\Programs\Podman\podman.EXE --connection pyrx-automation failed: stderr: Error: unable to start container "ec9cfc6b96f446f26c42dac78714f03f9b93a218557bcfdcb8597246a434459a": crun: open `memory.max` for writing: No such file or directory: OCI runtime attempted to invoke a command that was not found Test runs: none recorded. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
This is a nice refactor. One thing with allSubtypes: it passes the callback straight to Array.every, which calls it with (subtype, index, array). someSubtypes and the non-union path only pass the subtype, so callbacks with optional positional arguments can behave differently.
For example, take a union ordered as a literal followed by a Container specialized with that literal. containsLiteralType gives [true, false] when called on each member with the default includeTypeArgs, but allSubtypes(union, containsLiteralType) returns true. The second call gets index 1 as includeTypeArgs and checks the type arguments. Wrapping it as allSubtypes(union, subtype => containsLiteralType(subtype)) returns false. Reverse the members and both forms return false. Passing the function directly type-checks, which makes this easy to miss.
Could we wrap the callback passed to every, like subtype => callback(subtype), so it only gets the subtype? A focused test would be useful too.
The base already returned false for every non-empty union, and there's no current in-repo production caller using a multi-parameter callback. External callers weren't checked. So this looks like a latent issue in the helper fix, not a demonstrated Python regression.
Two smaller optional things: could the existing createClass in typeUtils.test.ts cover these tests instead of adding createClassType? It gives the same results for these tests, though the helpers have different metadata and MROs.
Would a direct unit test for isTypeVarSame be useful too? There isn't one now, and the ten cases checked matched base and head. That's just a coverage suggestion, not an observed behavior change.
Class B: Pyright helper contract. Pass only the subtype to each predicate so optional arguments retain their defaults. Preserve short-circuit behavior and literal-detection precision. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Pushed 7603cc8 and merged current main in 6191331. The core build, 26 utility/equality tests, 38 TypeVar/union tests, 128 mypy-primer workflow tests, ESLint, and Prettier passed on the merged branch. The wrapper removes the direct |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
/benchmark |
|
Compared candidate Release history charts were not rendered for this run. See the workflow run for details. Type checker benchmark🟢 No performance regressions detected. Regression threshold:
Pyright stats
|
Classification: C (test maintenance). No type precision changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
Compared candidate Release history charts were not rendered for this run. See the workflow run for details. Type checker benchmark🟢 No performance regressions detected. Regression threshold:
Pyright stats
|
Summary
allSubtypesso union checks return callback results.Array.everyfor allocation-free early termination.allSubtypesinisTypeVarSameto stop at the first incompatible subtype instead of walking the remaining union entries with no-op callbacks.someSubtypesand adds direct unit coverage for both helpers.This is the safe
typeUtilsportion split from #11419. It intentionally excludes the literal, tuple,derivesFromAnyOrUnknown, and NoReturn early exits that produced mypy_primer differences.Validation
pnpm exec jest typeUtils.test --forceExitpnpm run buildpnpm run check:prettierpnpm run check:eslint