-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
create_baseline_stubs.py: Improve pyright config file editing #10629
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
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.
This relies on us remembering to keep a trailing comma for the last element in the list, right? We could edit it manually (which we do from time to time) and forget to keep a trailing comma with the last element, and none of our tests would fail. Then if somebody came along and tried to add stubs for zzzzz
, the script would be broken.
We could possibly add a test to check_consistent.py
that asserts that the last element in the list has a trailing comma. But that seems like it could be even more complicated than what we have now
I have changed this PR to only fix the indexing bug, reverted other changes, and again tested it locally. Even though I still think the code looks like spaghetti, I cannot come up with anything significantly nicer. |
I mean, I don't disagree :) |
I think I managed to make it look less spaghetti-like, though it is longer than before. I again tested it locally. It now sorts the list every time, and turns out there were a few places where it wasn't sorted correctly. The only downside I can see is that the code is a bit longer than before. If we agree that this is a good idea, let's change the title of the PR before we merge. |
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.
This is a big readability improvement. Thanks!
# We assume that all third-party excludes must be at the end of the list. | ||
# This helps with skipping special entries, such as "stubs/**/@tests/test_cases". |
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.
Ideally we'd assert this somehow in check_consistent.py
, but I can't think of a simple way of doing so, and a complex way of doing so would probably be overkill for this use case. If this assumption becomes invalidated at some point, we can probably just deal with that when the problem arises.
There was an indexing bug that added a trailing comma to the wrong line. It happened every time someone added stubs for a new package whose name is alphabetically at the end of the list, and it looked like this. We don't really need indexing spaghetti to deal with commas, since pyright's "JSON" config file supports trailing commas anyway (even though plain old JSON does not).
Tested locally by deleting stubs and adding them back.