-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
chore: improve error message for undeclared enum member #3264
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #3264 +/- ##
==========================================
- Coverage 88.88% 88.60% -0.29%
==========================================
Files 84 84
Lines 10598 10599 +1
Branches 2212 2212
==========================================
- Hits 9420 9391 -29
- Misses 769 796 +27
- Partials 409 412 +3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@@ -55,6 +55,9 @@ def __init__(self, name: str, members: dict) -> None: | |||
# also conveniently checks well-formedness of the members namespace | |||
self._helper = VyperType(members) | |||
|
|||
# set the name for exception handling in `get_member` | |||
self._helper._id = name |
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.
Seems a bit funky, basically a side effect?
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.
Yes, so that it can be handled by L300 here:
vyper/vyper/semantics/types/base.py
Lines 291 to 303 in 02339df
def get_member(self, key: str, node: vy_ast.VyperNode) -> "VyperType": | |
if key in self.members: | |
return self.members[key] | |
# special error message for types with no members | |
if not self.members: | |
raise StructureException(f"{self} instance does not have members", node) | |
suggestions_str = get_levenshtein_error_suggestions(key, self.members, 0.3) | |
raise UnknownAttribute(f"{self} has no member '{key}'. {suggestions_str}", node) | |
def __repr__(self): | |
return self._id |
What I did
Fix #3262
How I did it
Set
EnumT._helper._id
to the same name as theEnumT
.How to verify it
See test.
Commit message
Description for the changelog
Improve error message for undeclared enum member
Cute Animal Picture