GeezerVison is showing github.com — The BDFL has retired! Long live the FLUFL (Friendly Language Uncle Fo… · Maddie-Code-Collab/cpython@e3944a5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Grammar/Grammar +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,7 +87,7 @@ or_test: and_test ('or' and_test)* | 87 | 87 | and_test: not_test ('and' not_test)* | 88 | 88 | not_test: 'not' not_test | comparison | 89 | 89 | comparison: star_expr (comp_op star_expr)* | 90 | | -comp_op: '<'|'>'|'=='|'>='|'<='|'!='|'in'|'not' 'in'|'is'|'is' 'not' | | 90 | +comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' | 91 | 91 | star_expr: ['*'] expr | 92 | 92 | expr: xor_expr ('|' xor_expr)* | 93 | 93 | xor_expr: and_expr ('^' and_expr)* | |
Collapse file Copy file name to clipboardExpand all lines: Include/code.h +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,10 +52,12 @@ typedef struct { | 52 | 52 | #define CO_FUTURE_UNICODE_LITERALS 0x20000 | 53 | 53 | #endif | 54 | 54 |
| | 55 | +#define CO_FUTURE_BARRY_AS_BDFL 0x40000 | | 56 | + | 55 | 57 | /* This should be defined if a future statement modifies the syntax. | 56 | 58 | For example, when a keyword is added. | 57 | 59 | */ | 58 | | -/* #define PY_PARSER_REQUIRES_FUTURE_KEYWORD */ | | 60 | +#define PY_PARSER_REQUIRES_FUTURE_KEYWORD | 59 | 61 |
| 60 | 62 | #define CO_MAXBLOCKS 20 /* Max static block nesting within a function */ | 61 | 63 |
| |
Collapse file Copy file name to clipboardExpand all lines: Include/compile.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,7 @@ typedef struct { | 26 | 26 | #define FUTURE_WITH_STATEMENT "with_statement" | 27 | 27 | #define FUTURE_PRINT_FUNCTION "print_function" | 28 | 28 | #define FUTURE_UNICODE_LITERALS "unicode_literals" | | 29 | +#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL" | 29 | 30 |
| 30 | 31 | struct _mod; /* Declare the existence of this type */ | 31 | 32 | PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *, | |
Collapse file Copy file name to clipboardExpand all lines: Include/parsetok.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,6 +30,7 @@ typedef struct { | 30 | 30 | #endif | 31 | 31 |
| 32 | 32 | #define PyPARSE_IGNORE_COOKIE 0x0010 | | 33 | +#define PyPARSE_BARRY_AS_BDFL 0x0020 | 33 | 34 |
| 34 | 35 | PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int, | 35 | 36 | perrdetail *); | |
Collapse file Copy file name to clipboardExpand all lines: Include/pythonrun.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | extern "C" { | 8 | 8 | #endif | 9 | 9 |
| 10 | | -#define PyCF_MASK 0 | | 10 | +#define PyCF_MASK CO_FUTURE_BARRY_AS_BDFL | 11 | 11 | #define PyCF_MASK_OBSOLETE 0 | 12 | 12 | #define PyCF_SOURCE_IS_UTF8 0x0100 | 13 | 13 | #define PyCF_DONT_IMPLY_DEDENT 0x0200 | |
Collapse file Copy file name to clipboardExpand all lines: Lib/__future__.py +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 70 | 70 | CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement | 71 | 71 | CO_FUTURE_PRINT_FUNCTION = 0x10000 # print function | 72 | 72 | CO_FUTURE_UNICODE_LITERALS = 0x20000 # unicode string literals | | 73 | +CO_FUTURE_BARRY_AS_BDFL = 0x40000 | 73 | 74 |
| 74 | 75 | class _Feature: | 75 | 76 | def __init__(self, optionalRelease, mandatoryRelease, compiler_flag): | @@ -126,3 +127,7 @@ def __repr__(self): | 126 | 127 | unicode_literals = _Feature((2, 6, 0, "alpha", 2), | 127 | 128 | (3, 0, 0, "alpha", 0), | 128 | 129 | CO_FUTURE_UNICODE_LITERALS) | | 130 | + | | 131 | +barry_as_FLUFL = _Feature((3, 1, 0, "alpha", 2), | | 132 | + (3, 9, 0, "alpha", 0), | | 133 | + CO_FUTURE_BARRY_AS_BDFL) |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import __future__ | | 2 | +import unittest | | 3 | + | | 4 | +class FLUFLTests(unittest.TestCase): | | 5 | + | | 6 | + def test_barry_as_bdfl(self): | | 7 | + code = "from __future__ import barry_as_FLUFL; 2 {0} 3" | | 8 | + compile(code.format('<>'), '<BDFL test>', 'exec', | | 9 | + __future__.CO_FUTURE_BARRY_AS_BDFL) | | 10 | + self.assertRaises(SyntaxError, compile, code.format('!='), | | 11 | + '<FLUFL test>', 'exec', | | 12 | + __future__.CO_FUTURE_BARRY_AS_BDFL) | | 13 | + | | 14 | + def test_guido_as_bdfl(self): | | 15 | + code = '2 {0} 3' | | 16 | + compile(code.format('!='), '<BDFL test>', 'exec') | | 17 | + self.assertRaises(SyntaxError, compile, code.format('<>'), | | 18 | + '<FLUFL test>', 'exec') | | 19 | + | | 20 | + | | 21 | +def test_main(): | | 22 | + from test.support import run_unittest | | 23 | + run_unittest(FLUFLTests) | | 24 | + | | 25 | + | | 26 | +if __name__ == '__main__': | | 27 | + test_main() |
Collapse file Copy file name to clipboardExpand all lines: Parser/parser.c +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -149,13 +149,15 @@ classify(parser_state *ps, int type, char *str) | 149 | 149 | strcmp(l->lb_str, s) != 0) | 150 | 150 | continue; | 151 | 151 | #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD | | 152 | +#if 0 | 152 | 153 | /* Leaving this in as an example */ | 153 | 154 | if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) { | 154 | 155 | if (s[0] == 'w' && strcmp(s, "with") == 0) | 155 | 156 | break; /* not a keyword yet */ | 156 | 157 | else if (s[0] == 'a' && strcmp(s, "as") == 0) | 157 | 158 | break; /* not a keyword yet */ | 158 | 159 | } | | 160 | +#endif | 159 | 161 | #endif | 160 | 162 | D(printf("It's a keyword\n")); | 161 | 163 | return n - i; | @@ -178,6 +180,7 @@ classify(parser_state *ps, int type, char *str) | 178 | 180 | } | 179 | 181 |
| 180 | 182 | #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD | | 183 | +#if 0 | 181 | 184 | /* Leaving this in as an example */ | 182 | 185 | static void | 183 | 186 | future_hack(parser_state *ps) | @@ -218,6 +221,7 @@ future_hack(parser_state *ps) | 218 | 221 | } | 219 | 222 | } | 220 | 223 | } | | 224 | +#endif | 221 | 225 | #endif /* future keyword */ | 222 | 226 |
| 223 | 227 | int | @@ -278,10 +282,12 @@ PyParser_AddToken(register parser_state *ps, register int type, char *str, | 278 | 282 | d->d_name, | 279 | 283 | ps->p_stack.s_top->s_state)); | 280 | 284 | #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD | | 285 | +#if 0 | 281 | 286 | if (d->d_name[0] == 'i' && | 282 | 287 | strcmp(d->d_name, | 283 | 288 | "import_stmt") == 0) | 284 | 289 | future_hack(ps); | | 290 | +#endif | 285 | 291 | #endif | 286 | 292 | s_pop(&ps->p_stack); | 287 | 293 | if (s_empty(&ps->p_stack)) { | @@ -296,9 +302,11 @@ PyParser_AddToken(register parser_state *ps, register int type, char *str, | 296 | 302 |
| 297 | 303 | if (s->s_accept) { | 298 | 304 | #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD | | 305 | +#if 0 | 299 | 306 | if (d->d_name[0] == 'i' && | 300 | 307 | strcmp(d->d_name, "import_stmt") == 0) | 301 | 308 | future_hack(ps); | | 309 | +#endif | 302 | 310 | #endif | 303 | 311 | /* Pop this dfa and try again */ | 304 | 312 | s_pop(&ps->p_stack); | |
Collapse file Copy file name to clipboardExpand all lines: Parser/parsetok.c +17-21Lines changed: 17 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -100,6 +100,7 @@ PyParser_ParseFileFlagsEx(FILE *fp, const char *filename, | 100 | 100 | } | 101 | 101 |
| 102 | 102 | #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD | | 103 | +#if 0 | 103 | 104 | static char with_msg[] = | 104 | 105 | "%s:%d: Warning: 'with' will become a reserved keyword in Python 2.6\n"; | 105 | 106 |
| @@ -114,6 +115,7 @@ warn(const char *msg, const char *filename, int lineno) | 114 | 115 | PySys_WriteStderr(msg, filename, lineno); | 115 | 116 | } | 116 | 117 | #endif | | 118 | +#endif | 117 | 119 |
| 118 | 120 | /* Parse input coming from the given tokenizer structure. | 119 | 121 | Return error code. */ | @@ -133,8 +135,8 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, | 133 | 135 | return NULL; | 134 | 136 | } | 135 | 137 | #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD | 136 | | - if (*flags & PyPARSE_WITH_IS_KEYWORD) | 137 | | - ps->p_flags |= CO_FUTURE_WITH_STATEMENT; | | 138 | + if (*flags & PyPARSE_BARRY_AS_BDFL) | | 139 | + ps->p_flags |= CO_FUTURE_BARRY_AS_BDFL; | 138 | 140 | #endif | 139 | 141 |
| 140 | 142 | for (;;) { | @@ -177,26 +179,20 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, | 177 | 179 | str[len] = '\0'; | 178 | 180 |
| 179 | 181 | #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD | 180 | | - /* This is only necessary to support the "as" warning, but | 181 | | - we don't want to warn about "as" in import statements. */ | 182 | | - if (type == NAME && | 183 | | - len == 6 && str[0] == 'i' && strcmp(str, "import") == 0) | 184 | | - handling_import = 1; | 185 | | - | 186 | | - /* Warn about with as NAME */ | 187 | | - if (type == NAME && | 188 | | - !(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) { | 189 | | - if (len == 4 && str[0] == 'w' && strcmp(str, "with") == 0) | 190 | | - warn(with_msg, err_ret->filename, tok->lineno); | 191 | | - else if (!(handling_import || handling_with) && | 192 | | - len == 2 && str[0] == 'a' && | 193 | | - strcmp(str, "as") == 0) | 194 | | - warn(as_msg, err_ret->filename, tok->lineno); | | 182 | + if (type == NOTEQUAL) { | | 183 | + if (!(ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) && | | 184 | + strcmp(str, "!=")) { | | 185 | + err_ret->error = E_SYNTAX; | | 186 | + break; | | 187 | + } | | 188 | + else if ((ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) && | | 189 | + strcmp(str, "<>")) { | | 190 | + err_ret->text = "with Barry as BDFL, use '<>' " | | 191 | + "instead of '!='"; | | 192 | + err_ret->error = E_SYNTAX; | | 193 | + break; | | 194 | + } | 195 | 195 | } | 196 | | - else if (type == NAME && | 197 | | - (ps->p_flags & CO_FUTURE_WITH_STATEMENT) && | 198 | | - len == 4 && str[0] == 'w' && strcmp(str, "with") == 0) | 199 | | - handling_with = 1; | 200 | 196 | #endif | 201 | 197 | if (a >= tok->line_start) | 202 | 198 | col_offset = a - tok->line_start; | |
Collapse file Copy file name to clipboardExpand all lines: Parser/tokenizer.c +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1040,6 +1040,7 @@ PyToken_TwoChars(int c1, int c2) | 1040 | 1040 | break; | 1041 | 1041 | case '<': | 1042 | 1042 | switch (c2) { | | 1043 | + case '>': return NOTEQUAL; | 1043 | 1044 | case '=': return LESSEQUAL; | 1044 | 1045 | case '<': return LEFTSHIFT; | 1045 | 1046 | } | |
|