-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Support error codes from plugins in options #19719
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3ebd792
Support error codes from plugins in options
sigvef 9130edf
refactor error callback (#1)
belm0 60ab748
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 53a65f2
fix type check
belm0 5d72e39
Update main.py
ilevkivskyi 892ad6e
Update options.py
ilevkivskyi 5de7da2
Update build.py
ilevkivskyi 7691315
Update cmdline.test
ilevkivskyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| [case testCustomErrorCodeFromPluginIsTargetable] | ||
| # flags: --config-file tmp/mypy.ini --show-error-codes | ||
|
|
||
| def main() -> None: | ||
| return | ||
| main() # E: Custom error [custom] | ||
|
|
||
| [file mypy.ini] | ||
| \[mypy] | ||
| plugins=<ROOT>/test-data/unit/plugins/custom_errorcode.py | ||
|
|
||
| [case testCustomErrorCodeCanBeDisabled] | ||
| # flags: --config-file tmp/mypy.ini --show-error-codes --disable-error-code=custom | ||
|
|
||
| def main() -> None: | ||
| return | ||
| main() # no output expected when disabled | ||
|
|
||
| [file mypy.ini] | ||
| \[mypy] | ||
| plugins=<ROOT>/test-data/unit/plugins/custom_errorcode.py | ||
|
|
||
| [case testCustomErrorCodeCanBeReenabled] | ||
| # flags: --config-file tmp/mypy.ini --show-error-codes --disable-error-code=custom --enable-error-code=custom | ||
|
|
||
| def main() -> None: | ||
| return | ||
| main() # E: Custom error [custom] | ||
|
|
||
| [file mypy.ini] | ||
| \[mypy] | ||
| plugins=<ROOT>/test-data/unit/plugins/custom_errorcode.py |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't like this pattern (callback that stores another callback). Instead you should simply use another way to create a blocker error, e.g. use
raise CompileError(...)as aerror_callbacktoprocess_error_codes()after the plugins are loaded.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.
I made a refactor for this, but I don't have permission to commit to the PR.
@sigvef would you merge sigvef#1 or else grant me write permission on your fork?
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.
Nice! I added you as a collaborator on the fork, feel free to modify as you see fit!
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.
thank you-- committed callback refactor
Uh oh!
There was an error while loading. Please reload this page.
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.
@ilevkivskyi raising
CompileErrorrather than callingparser.error()has a subtly different result, since only the latter will output CLI usage with the error. Are you sure about this change?Test expectations fail as follows:
Personally, I think
parser.error()is the best for consistency with other parsing error cases. I wouldn't expect a different behavior only because a check needs to be deferred.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.
It is fine (and probably even good) to not have the
usage: ...part in this error. But I would add themypy: error:prefix.But also what you did is not what I wanted, the whole "double-callback" logic is pointless, you can simply call
options.process_error_codes()directly inbuild.py.