-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
Disallow use of None
, disallow use of del
, implemented clear()
built-in function.
#1106
Conversation
@fubuloubu @jacqueswww Quick question: Is the description of handling the replacement for If no, I believe that this PR is basically ready for review. There are some minor things we would have to either adjust with If yes, I have been doing a bit of diving into the solution for that but probably have a couple more questions 😅 |
@jakerockland I don't think you should implement that suggestion as it's a little bit "magical". It should be a further suggestion explored in a different VIP. |
Also, correct me if I'm wrong, but I think |
None
None
None
None
, implemented reset()
built-in function.
None
, implemented reset()
built-in function.None
, implemented reset()
built-in function.
Fixed test name Basic implementation of reset() functionality Catch use of None at pre-parser stage Reset from both memory and storage Removed unnecessary usage of None in other tests and added more testing for usage of None Reworked approach to implementing reset function, updated tests Refactored, finished testing suite Make the linter happy Disallow use of None at a syntax level, implement build-in reset() function
80de5ad
to
2a26431
Compare
@fubuloubu @jacqueswww Squashed my commits here, I believe this one is ready for review! |
vyper/parser/pre_parser.py
Outdated
@@ -49,6 +52,9 @@ def pre_parse(code): | |||
# Prevent semi-colon line statements. | |||
elif (token.type, token.string) == (OP, ";"): | |||
raise StructureException("Semi-colon statements not allowed.", token.start) | |||
# Prevent use of None literal |
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 blocks None
at the tokenization stage, but a user might want to make a contract or function named None
(weird, I know). I'm thinking this exception should be moved to a later stage - https://github.com/ethereum/vyper/blob/921bb80cf59c9be0067ed20e1a7b6ad0b59598b3/vyper/parser/expr.py#L147.
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.
@charles-cooper Yeah so that's actually intentional haha. 😅I previously had this set up to block at a later stage, when checking assignments or comparisons. Refactored though because it just generally seems like something to prevent a user from doing even if they want to, because it is confusing given that Vyper is based mostly on Python's syntax and would allow for potentially very misleading code (where one thinks a custom type or custom struct named None
is the Python None
but its actually some custom thing called None
.
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 think the best thing in that case would be if we just add None
as 'n reserved keyword?
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.
@jacqueswww That makes sense, just pushed a commit that implements that approach instead.
vyper/parser/stmt.py
Outdated
@@ -235,7 +251,10 @@ def call(self): | |||
) | |||
if isinstance(self.stmt.func, ast.Name): | |||
if self.stmt.func.id in stmt_dispatch_table: | |||
return stmt_dispatch_table[self.stmt.func.id](self.stmt, self.context) | |||
if self.stmt.func.id == 'reset': |
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 seems interesting .. why not just put the implementation in the dispatch table?
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.
@charles-cooper Doesn't work without serious refactoring given that the reset()
function self-mutates its input stmt
, which is different than all the other functions in the stmt_dispatch_table
.
One open question here is if |
One open question here is if |
Oh, I quite like |
…ection of the docs, added more tests
None
, implemented reset()
built-in function.None
, implemented clear()
built-in function.
None
, implemented clear()
built-in function.None
, disallow use of del
, implemented clear()
built-in function.
@jacqueswww Updated this PR to disallow usage of |
… expression evaluation rather than in pre-parser, more tests
@jacqueswww Updated this branch to use the new struct syntax in testing and resolved merge conflicts. |
@jacqueswww I'm a bit confused why Travis is failing with:
It doesn't seem relevant to the changes made in this PR, guessing something with Travis config may have gotten borked? |
Strange indeed. |
@jacqueswww Seems like it also isn't just an issue with this branch, #1125 seems to be failing for the same reason 😓 Is it possible to just trigger a re-build on Travis? |
…ssignments, added aditional tests
@jacqueswww HAZAH! Travis seems to be happily working now and also updated to work with some upstream changes that have happened since last update. |
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.
@jakerockland LGTM, please add changelog entry for clear here: https://github.com/ethereum/vyper/blob/master/docs/index.rst#compatibility-breaking-changelog
vyper/utils.py
Outdated
@@ -148,7 +148,7 @@ def in_bounds(cls, type_str, value): | |||
'pass', 'def', 'push', 'dup', 'swap', 'send', 'call', | |||
'selfdestruct', 'assert', 'stop', 'throw', | |||
'raise', 'init', '_init_', '___init___', '____init____', | |||
'true', 'false', 'self', 'this', 'continue', | |||
'true', 'false', 'self', 'this', 'continue', 'none', |
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.
Should clear become a reserved keyword?
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.
Yup
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.
Just pushed a PR that added clear
as a reserved word and added a entry to changelog.
- What I did
Implemented #539. Disallow use of
None
at the syntax level and implemented a built-in functionclear()
.- How I did it
Created special self-modifying statement function within
stmt.py
, updated tests that were previously using assignment toNone
, added comprehensive tests totest_clear.py
.- How to verify it
Added comprehensive tests, all that needs to be done is:
- Description for the changelog
Disallow use of
None
, disallow use ofdel
, implementedclear()
built-in function.- Cute Animal Picture