-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Improve --update-data handler #15283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ea590fb
to
9f2425a
Compare
This comment has been minimized.
This comment has been minimized.
1 similar comment
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
84fc792
to
e76f087
Compare
@JelleZijlstra @hauntsaninja Finally (a) merged all those branch-out PRs, and (b) squashed that Windows bug in my test, so it's ready for review |
e47b5a4
to
cf9e0d6
Compare
# start from end to prevent line offsets from shifting as we update | ||
for fix in sorted(self._fixes, reverse=True): | ||
lines[fix.lineno - 1 : fix.end_lineno - 1] = fix.lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A different approach here could have me parse the file, then re-write it while substituting specific sections (i.e. self._fixes
would be a mapping of sections to lines), but I think this approach is simple enough.
@hauntsaninja ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is awesome! Tried it out and it worked great on check tests.
Was playing around with this a little more, I think it should probably ignore xfail tests? |
Does it end up changing xfail'd tests? Hmpf. Yes, ignoring is the right thing to do (#15337). |
This PR seems to cause a failure in the wheel build. Strangely enough only with |
I think it's a cwd problem, see #15383. The errors across macos and linux appear to be the same. stdout
stderr
|
This should allow the inner pytest to pass even when the outer pytest is invoked outside of the mypy root, e.g. ```shell cd .. pytest mypy/mypy/test/testupdatedata.py ``` Addresses #15283 (comment).
I was playing around with this and I think it breaks on multiple errors? I'm getting test case headers overwritten! Might just be a user error though. |
@A5rocks Try running Easiest improvement would be probably to either error out when Another option would be to associate changes with identifiers ("update section Y of testcase X to Z"), then parse the file and replay them. Right now the update stage is simple/naive since at that point it's just replacing ranges of lines, not parsing any "INI" structure. (And, of course, we'd still need to hold a lock during the update.) |
That's probably it. Thanks! |
Fixes a [gotcha](#15283 (comment)) with `--update-data`. When using `--update-data` with parallelized tests (xdist), the line offsets determined at test time may become wrong by update time, as multiple workers perform their updates to the same file. This makes it so we exit with a usage error when `--update-data` is used with parallelism.
Fixes #15265.
The new implementation works for two kinds of 'check' tests:
[out]
and/or[outN]
sections, have those sections rewritten with the new results[case ...]
and[file ...]
sections, have the actual results inlined into source codeThe two scenarios are mutually exclusive: if
[out]
is updated, then[case ...]
won't be.Details:
The "fixes" are enqueued and applied in reverse order to prevent line offsets from shifting as it incrementally changes the file.
The update preserves spacing between the source code and comment to reduce diff noise.
Like the previous implementation, we only update "check" data tests.