-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Update remaining code to use new diagnostics #606
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
04282ac
feat: Update top-level definitions to use new diagnostics
mark-koch ac682d3
feat: Update type parsing to use new diagnostics
mark-koch 611a006
feat: Update remaining code to use new diagnostics
mark-koch 0b3a662
Set singular=True
mark-koch 978e0f2
Refactor zero check
mark-koch 2b23832
Register default child diagnostics in __post_init__
mark-koch afe8801
Move custom function parsing out of decorator and add test
mark-koch d8b5c78
Add NoSignatureError.Suggestion by default
mark-koch a7f6aa1
Improve coverage
mark-koch 52e7221
Merge branch 'diag/defs' into diag/tys
mark-koch d0950c9
Merge branch 'diag/defs' into diag/rest
mark-koch a6f615a
Make suggestions default child diagnostics
mark-koch 575d373
Merge branch 'diag/tys' into diag/rest
mark-koch 2b69b80
Merge remote-tracking branch 'origin/feat/diagnostics' into diag/rest
mark-koch 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 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 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 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 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 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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
from ast import expr | ||
from dataclasses import dataclass | ||
from types import TracebackType | ||
from typing import ClassVar | ||
|
||
from guppylang.ast_util import AstNode | ||
from guppylang.diagnostic import Error, Help | ||
from guppylang.error import GuppyError | ||
|
||
EXPERIMENTAL_FEATURES_ENABLED = False | ||
|
@@ -55,19 +58,29 @@ def __exit__( | |
EXPERIMENTAL_FEATURES_ENABLED = self.original | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ExperimentalFeatureError(Error): | ||
title: ClassVar[str] = "Experimental feature" | ||
span_label: ClassVar[str] = "{things} are an experimental feature" | ||
things: str | ||
|
||
@dataclass(frozen=True) | ||
class Suggestion(Help): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this error ever going to be created without adding this Help? |
||
message: ClassVar[str] = ( | ||
"Experimental features are currently disabled. You can enable them by " | ||
"calling `guppylang.enable_experimental_features()`, however note that " | ||
"these features are unstable and might break in the future." | ||
) | ||
|
||
def __post_init__(self) -> None: | ||
self.add_sub_diagnostic(ExperimentalFeatureError.Suggestion(None)) | ||
|
||
|
||
def check_function_tensors_enabled(node: expr | None = None) -> None: | ||
if not EXPERIMENTAL_FEATURES_ENABLED: | ||
raise GuppyError( | ||
"Function tensors are an experimental feature. Use " | ||
"`guppylang.enable_experimental_features()` to enable them.", | ||
node, | ||
) | ||
raise GuppyError(ExperimentalFeatureError(node, "Function tensors")) | ||
|
||
|
||
def check_lists_enabled(loc: AstNode | None = None) -> None: | ||
if not EXPERIMENTAL_FEATURES_ENABLED: | ||
raise GuppyError( | ||
"Lists are an experimental feature and not fully supported yet. Use " | ||
"`guppylang.enable_experimental_features()` to enable them.", | ||
loc, | ||
) | ||
raise GuppyError(ExperimentalFeatureError(loc, "Lists")) |
This file contains 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
Oops, something went wrong.
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.
Guppy errors are now reserved for things that go wrong during compilation. This error is thrown immediately when the user calls the decorator, so we shouldn't use
GuppyError
Same for other errors in this file