
On Wed May 16 20:53:46 EDT 2018, Steven D'Aprano wrote:
If it was possible to consider any syntactical block for the declarations, this use case could be handled like: try: nonkeyword except value = data.except except: value = data.missing() Alternatively, data.except could be allowed even without a declaration as another idea suggests. There are syntactical positions where it is easy to distinguish between a keyword and an identifier, there are positions where it is harder, or even impossible due to limitations on the parser complexity. So both ideas may be viewed as complementary, and the base case of my proposal would be just a per module opt out from a keyword, so it is easier to fix such module when a new keyword is introduced in the language.
None is a different kind of keyword. Ordinary keywords that make the statements of the language have no value, so 'x = if' makes no sense. On the other hand, None, True, and False are singleton values (like Ellispsis and NotImplemented) that are additionally protected from be redefined, which makes them similar to keywords. I think that the barrier for adding new keyword constants is even higher than the barrier for adding new ordinary keywords, and so may be omited when trying to solve the keyword/identifier problem. nonkeyword None # SyntaxError: a keyword constant 'None' cannot be an identifier
Remember the KISS principle.
It seemed to me that the syntactical block based declarations are quite simple in principle, but you are right, there are many issues. Best regards, Adam Bartoš
participants (1)
-
Adam Bartoš