-
-
Notifications
You must be signed in to change notification settings - Fork 865
feat(flag): enable iteration via Flag.__values__ #4739
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
base: master
Are you sure you want to change the base?
Conversation
- Add Flag.__values__ type member returning SArray[Flag] - Codegen: materialize Flag.__values__ as static array of flag bitmasks - Analysis: remove iteration over Flag type; require array/list iterator - Codegen: drop For-over-flag-type path; use list/array iteration only - Docs: update iteration section to use Flag.__values__ - Tests: update flag iteration tests to use __values__ BREAKING CHANGE: Iterating a flag type now requires using Flag.__values__ rather than the type itself.\n
Move HashMapT and SArrayT imports to local scope to avoid circular dependency
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4739 +/- ##
==========================================
+ Coverage 93.06% 93.20% +0.14%
==========================================
Files 131 131
Lines 19134 19180 +46
Branches 3323 3295 -28
==========================================
+ Hits 17807 17877 +70
+ Misses 894 884 -10
+ Partials 433 419 -14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
there was the movement of an import that we might want to do, but is unrelated to the changes introduced in this PR
vyper/semantics/types/user.py
Outdated
def get_type_member(self, key: str, node: vy_ast.VyperNode) -> "VyperType": | ||
# Special iterator helper for flags: `Flag.__values__` | ||
# Returns a static array type of all flag values in declaration order. | ||
if key == "__values__": |
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.
why don't we actually put it on the flag type?
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 just thought this syntax looked weird
for f: Foo in Foo:
...
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.
no i'm not talking about the user-facing semantics, i'm saying why don't we add it to the members dict on the flag type?
Thanks again for the nudge here. I have moved the flag constants (and |
|
||
# set the name for exception handling in `get_member` | ||
self._helper._id = name | ||
from vyper.semantics.types.subscriptable import SArrayT |
Check notice
Code scanning / CodeQL
Cyclic import Note
Summary
This PR modifies the Flag type to allow explicit iteration through the
__values__
attributeChanges
__values__
Test plan