https://github.com/python/cpython/commit/66f8dbe0f53db72cb3e728ae153156ca993dd025
commit: 66f8dbe0f53db72cb3e728ae153156ca993dd025
branch: 3.14
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-09-25T20:38:45Z
summary:

[3.14] gh-151464: exclude '<>' token from tokenize output (GH-154854) (#158190)

* gh-151464: exclude '<>' token from tokenize output

Was:
```
$ echo '1 <> 2' | python -m tokenize
1,0-1,1:            NUMBER         '1'
1,2-1,4:            OP             '<>'
1,5-1,6:            NUMBER         '2'
1,6-1,7:            NEWLINE        '\n'
2,0-2,0:            ENDMARKER      ''
```

Now (regardless on ``__future__.barry_as_FLUFL`` import):
```
$ echo '1 <> 2' | ./python -m tokenize
1,0-1,1:            NUMBER         '1'
1,2-1,3:            OP             '<'
1,3-1,4:            OP             '>'
1,5-1,6:            NUMBER         '2'
1,6-1,7:            NEWLINE        '\n'
2,0-2,0:            ENDMARKER      ''
```
in accordance with the Grammar:
https://docs.python.org/3.14/reference/lexical_analysis.html#operators-and-delimiters

Also adds a custom error message for ``<>`` ("not equal" in Pascal
and Python 2).

* +1

* address review: lowercase and move invalid rule

* address review: news

* address review: move test_guido_as_bdfl_ineq_tokens()

* address review: revert _PyTokenizer_From* changes

* + revert unrelated change

* address review: remove whatsnew entry

(cherry picked from commit 198bc7683641f6b44d23fe5dc228f732a7cf3df8)

Co-authored-by: Sergey B Kirpichev <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-07-29-08-43-14.gh-issue-151464.o_mtmz.rst
M Grammar/python.gram
M Lib/test/test_syntax.py
M Lib/test/test_tokenize.py
M Parser/action_helpers.c
M Parser/lexer/lexer.c
M Parser/lexer/state.h
M Parser/parser.c
M Parser/pegen.c
M Parser/pegen.h

diff --git a/Grammar/python.gram b/Grammar/python.gram
index 7b27b04bf7989e..a564077381676d 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -774,6 +774,7 @@ compare_op_bitwise_or_pair[CmpopExprPair*]:
     | eq_bitwise_or
     | noteq_bitwise_or
     | lte_bitwise_or
+    | invalid_noteq
     | lt_bitwise_or
     | gte_bitwise_or
     | gt_bitwise_or
@@ -1567,3 +1568,10 @@ invalid_type_params:
         RAISE_SYNTAX_ERROR_STARTING_FROM(
             token,
             "Type parameter list cannot be empty")}
+
+invalid_noteq:
+    | a='<' b='>' {
+        _PyPegen_tokens_are_adjacent(a, b)
+        ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax.  Maybe you 
meant '!=' instead of '<>'?")
+        : NULL
+    }
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index c11822333f4c7e..cfb7cab093eb8b 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -3329,6 +3329,30 @@ def test_ifexp_body_stmt_else_stmt(self):
         ]:
             self._check_error(f"x = {lhs_stmt} if 1 else {rhs_stmt}", msg)
 
+    def test_diamond_operator(self):
+        self._check_error(
+            "1<>2",
+            r"Maybe you meant '!=' instead of '<>'\?",
+            lineno=1,
+            end_lineno=1,
+            offset=2,
+            end_offset=4,
+        )
+
+    def test_diamond_operator_barry_as_flufl(self):
+        compile(
+            "from __future__ import barry_as_FLUFL\n1<>2",
+            "<test>", "exec",
+        )
+        self._check_error(
+            "from __future__ import barry_as_FLUFL\na != b",
+            "with Barry as BDFL, use '<>' instead of '!='",
+            lineno=2,
+            end_lineno=2,
+            offset=3,
+            end_offset=5,
+        )
+
 def load_tests(loader, tests, pattern):
     tests.addTest(doctest.DocTestSuite())
     return tests
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index ca67e381958757..56c05bf15de237 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -1233,6 +1233,20 @@ def test_multiline_non_ascii_fstring_with_expr(self):
     FSTRING_END \'"\'           (2, 2) (2, 3)
     """)
 
+    def test_ineq_tokens(self):
+        self.check_tokenize("1 != 2", """\
+    NUMBER     '1'           (1, 0) (1, 1)
+    OP         '!='          (1, 2) (1, 4)
+    NUMBER     '2'           (1, 5) (1, 6)
+""")
+        self.check_tokenize("1 <> 2", """\
+    NUMBER     '1'           (1, 0) (1, 1)
+    OP         '<'           (1, 2) (1, 3)
+    OP         '>'           (1, 3) (1, 4)
+    NUMBER     '2'           (1, 5) (1, 6)
+""")
+
+
 class GenerateTokensTest(TokenizeTest):
     def check_tokenize(self, s, expected):
         # Format the tokens in s in a table format.
diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-07-29-08-43-14.gh-issue-151464.o_mtmz.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-29-08-43-14.gh-issue-151464.o_mtmz.rst
new file mode 100644
index 00000000000000..ba7dbe13254037
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-29-08-43-14.gh-issue-151464.o_mtmz.rst
@@ -0,0 +1,2 @@
+Exclude invalid token ``<>`` from :mod:`tokenize` output.  :exc:`SyntaxError`
+for ``<>`` now suggests ``!=``.
diff --git a/Parser/action_helpers.c b/Parser/action_helpers.c
index de5ef174553c60..3c111307240097 100644
--- a/Parser/action_helpers.c
+++ b/Parser/action_helpers.c
@@ -5,6 +5,7 @@
 
 #include "pegen.h"
 #include "string_parser.h"          // _PyPegen_decode_string()
+#include "lexer/state.h"            // tok_state
 
 
 void *
@@ -1979,6 +1980,7 @@ _PyPegen_checked_future_import(Parser *p, identifier 
module, asdl_alias_seq * na
             alias_ty alias = asdl_seq_GET(names, i);
             if (PyUnicode_CompareWithASCIIString(alias->name, 
"barry_as_FLUFL") == 0) {
                 p->flags |= PyPARSE_BARRY_AS_BDFL;
+                p->tok->barry_as_bdfl = 1;
             }
         }
     }
diff --git a/Parser/lexer/lexer.c b/Parser/lexer/lexer.c
index 58cba820775782..af57deb12cbefb 100644
--- a/Parser/lexer/lexer.c
+++ b/Parser/lexer/lexer.c
@@ -1235,6 +1235,9 @@ tok_get_normal_mode(struct tok_state *tok, 
tokenizer_mode* current_tok, struct t
     {
         int c2 = tok_nextc(tok);
         int current_token = _PyToken_TwoChars(c, c2);
+        if (c == '<' && c2 == '>' && !tok->barry_as_bdfl) {
+            current_token = OP;
+        }
         if (current_token != OP) {
             int c3 = tok_nextc(tok);
             int current_token3 = _PyToken_ThreeChars(c, c2, c3);
diff --git a/Parser/lexer/state.h b/Parser/lexer/state.h
index 31751963964bba..56db4dda2798eb 100644
--- a/Parser/lexer/state.h
+++ b/Parser/lexer/state.h
@@ -137,6 +137,7 @@ struct tok_state {
 #ifdef Py_DEBUG
     int debug;
 #endif
+    int barry_as_bdfl;
 };
 
 int _PyLexer_type_comment_token_setup(struct tok_state *tok, struct token 
*token, int type, int col_offset,
diff --git a/Parser/parser.c b/Parser/parser.c
index 3f06abc2a4854a..4d02d9ca5ec486 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -352,183 +352,184 @@ static char *soft_keywords[] = {
 #define invalid_arithmetic_type 1265
 #define invalid_factor_type 1266
 #define invalid_type_params_type 1267
-#define _loop0_1_type 1268
-#define _loop1_2_type 1269
-#define _loop0_3_type 1270
-#define _gather_4_type 1271
-#define _tmp_5_type 1272
-#define _tmp_6_type 1273
-#define _tmp_7_type 1274
-#define _tmp_8_type 1275
-#define _tmp_9_type 1276
-#define _tmp_10_type 1277
-#define _tmp_11_type 1278
-#define _loop1_12_type 1279
-#define _tmp_13_type 1280
-#define _loop0_14_type 1281
-#define _gather_15_type 1282
-#define _tmp_16_type 1283
-#define _tmp_17_type 1284
-#define _loop0_18_type 1285
-#define _loop1_19_type 1286
-#define _loop0_20_type 1287
-#define _gather_21_type 1288
-#define _tmp_22_type 1289
-#define _loop0_23_type 1290
-#define _gather_24_type 1291
-#define _loop1_25_type 1292
-#define _tmp_26_type 1293
-#define _tmp_27_type 1294
-#define _loop0_28_type 1295
-#define _loop0_29_type 1296
-#define _loop1_30_type 1297
-#define _loop1_31_type 1298
-#define _loop0_32_type 1299
-#define _loop1_33_type 1300
-#define _loop0_34_type 1301
-#define _gather_35_type 1302
-#define _tmp_36_type 1303
-#define _loop1_37_type 1304
-#define _loop1_38_type 1305
-#define _loop1_39_type 1306
-#define _loop0_40_type 1307
-#define _gather_41_type 1308
-#define _tmp_42_type 1309
-#define _tmp_43_type 1310
-#define _tmp_44_type 1311
-#define _loop0_45_type 1312
-#define _gather_46_type 1313
-#define _loop0_47_type 1314
-#define _gather_48_type 1315
-#define _tmp_49_type 1316
-#define _loop0_50_type 1317
-#define _gather_51_type 1318
-#define _loop0_52_type 1319
-#define _gather_53_type 1320
-#define _loop0_54_type 1321
-#define _gather_55_type 1322
-#define _loop1_56_type 1323
-#define _loop1_57_type 1324
-#define _loop0_58_type 1325
-#define _gather_59_type 1326
-#define _loop1_60_type 1327
-#define _loop1_61_type 1328
-#define _loop1_62_type 1329
-#define _tmp_63_type 1330
-#define _loop0_64_type 1331
-#define _gather_65_type 1332
-#define _tmp_66_type 1333
-#define _tmp_67_type 1334
-#define _tmp_68_type 1335
-#define _tmp_69_type 1336
-#define _tmp_70_type 1337
-#define _loop0_71_type 1338
-#define _loop0_72_type 1339
-#define _loop1_73_type 1340
-#define _loop1_74_type 1341
-#define _loop0_75_type 1342
-#define _loop1_76_type 1343
-#define _loop0_77_type 1344
-#define _loop0_78_type 1345
-#define _loop0_79_type 1346
-#define _loop0_80_type 1347
-#define _loop1_81_type 1348
-#define _loop1_82_type 1349
-#define _tmp_83_type 1350
-#define _loop0_84_type 1351
-#define _gather_85_type 1352
-#define _loop1_86_type 1353
-#define _loop0_87_type 1354
-#define _tmp_88_type 1355
-#define _loop0_89_type 1356
-#define _gather_90_type 1357
-#define _tmp_91_type 1358
-#define _loop0_92_type 1359
-#define _gather_93_type 1360
-#define _loop0_94_type 1361
-#define _gather_95_type 1362
-#define _loop0_96_type 1363
-#define _loop0_97_type 1364
-#define _gather_98_type 1365
-#define _loop1_99_type 1366
-#define _tmp_100_type 1367
-#define _loop0_101_type 1368
-#define _gather_102_type 1369
-#define _loop0_103_type 1370
-#define _gather_104_type 1371
-#define _tmp_105_type 1372
-#define _tmp_106_type 1373
-#define _loop0_107_type 1374
-#define _gather_108_type 1375
-#define _tmp_109_type 1376
-#define _tmp_110_type 1377
-#define _tmp_111_type 1378
-#define _tmp_112_type 1379
-#define _tmp_113_type 1380
-#define _loop1_114_type 1381
-#define _tmp_115_type 1382
-#define _tmp_116_type 1383
-#define _tmp_117_type 1384
-#define _tmp_118_type 1385
-#define _tmp_119_type 1386
-#define _loop0_120_type 1387
-#define _loop0_121_type 1388
-#define _tmp_122_type 1389
-#define _tmp_123_type 1390
-#define _tmp_124_type 1391
-#define _tmp_125_type 1392
-#define _tmp_126_type 1393
-#define _tmp_127_type 1394
-#define _tmp_128_type 1395
-#define _tmp_129_type 1396
-#define _tmp_130_type 1397
-#define _loop0_131_type 1398
-#define _gather_132_type 1399
-#define _tmp_133_type 1400
-#define _tmp_134_type 1401
-#define _tmp_135_type 1402
-#define _tmp_136_type 1403
-#define _loop0_137_type 1404
-#define _gather_138_type 1405
-#define _tmp_139_type 1406
-#define _loop0_140_type 1407
-#define _gather_141_type 1408
-#define _loop0_142_type 1409
-#define _gather_143_type 1410
-#define _tmp_144_type 1411
-#define _loop0_145_type 1412
-#define _tmp_146_type 1413
-#define _tmp_147_type 1414
-#define _tmp_148_type 1415
-#define _tmp_149_type 1416
-#define _tmp_150_type 1417
-#define _tmp_151_type 1418
-#define _tmp_152_type 1419
-#define _tmp_153_type 1420
-#define _tmp_154_type 1421
-#define _tmp_155_type 1422
-#define _tmp_156_type 1423
-#define _tmp_157_type 1424
-#define _tmp_158_type 1425
-#define _tmp_159_type 1426
-#define _tmp_160_type 1427
-#define _tmp_161_type 1428
-#define _tmp_162_type 1429
-#define _tmp_163_type 1430
-#define _tmp_164_type 1431
-#define _tmp_165_type 1432
-#define _tmp_166_type 1433
-#define _tmp_167_type 1434
-#define _tmp_168_type 1435
-#define _tmp_169_type 1436
-#define _tmp_170_type 1437
-#define _tmp_171_type 1438
-#define _loop0_172_type 1439
-#define _tmp_173_type 1440
-#define _tmp_174_type 1441
-#define _tmp_175_type 1442
-#define _tmp_176_type 1443
-#define _tmp_177_type 1444
+#define invalid_noteq_type 1268
+#define _loop0_1_type 1269
+#define _loop1_2_type 1270
+#define _loop0_3_type 1271
+#define _gather_4_type 1272
+#define _tmp_5_type 1273
+#define _tmp_6_type 1274
+#define _tmp_7_type 1275
+#define _tmp_8_type 1276
+#define _tmp_9_type 1277
+#define _tmp_10_type 1278
+#define _tmp_11_type 1279
+#define _loop1_12_type 1280
+#define _tmp_13_type 1281
+#define _loop0_14_type 1282
+#define _gather_15_type 1283
+#define _tmp_16_type 1284
+#define _tmp_17_type 1285
+#define _loop0_18_type 1286
+#define _loop1_19_type 1287
+#define _loop0_20_type 1288
+#define _gather_21_type 1289
+#define _tmp_22_type 1290
+#define _loop0_23_type 1291
+#define _gather_24_type 1292
+#define _loop1_25_type 1293
+#define _tmp_26_type 1294
+#define _tmp_27_type 1295
+#define _loop0_28_type 1296
+#define _loop0_29_type 1297
+#define _loop1_30_type 1298
+#define _loop1_31_type 1299
+#define _loop0_32_type 1300
+#define _loop1_33_type 1301
+#define _loop0_34_type 1302
+#define _gather_35_type 1303
+#define _tmp_36_type 1304
+#define _loop1_37_type 1305
+#define _loop1_38_type 1306
+#define _loop1_39_type 1307
+#define _loop0_40_type 1308
+#define _gather_41_type 1309
+#define _tmp_42_type 1310
+#define _tmp_43_type 1311
+#define _tmp_44_type 1312
+#define _loop0_45_type 1313
+#define _gather_46_type 1314
+#define _loop0_47_type 1315
+#define _gather_48_type 1316
+#define _tmp_49_type 1317
+#define _loop0_50_type 1318
+#define _gather_51_type 1319
+#define _loop0_52_type 1320
+#define _gather_53_type 1321
+#define _loop0_54_type 1322
+#define _gather_55_type 1323
+#define _loop1_56_type 1324
+#define _loop1_57_type 1325
+#define _loop0_58_type 1326
+#define _gather_59_type 1327
+#define _loop1_60_type 1328
+#define _loop1_61_type 1329
+#define _loop1_62_type 1330
+#define _tmp_63_type 1331
+#define _loop0_64_type 1332
+#define _gather_65_type 1333
+#define _tmp_66_type 1334
+#define _tmp_67_type 1335
+#define _tmp_68_type 1336
+#define _tmp_69_type 1337
+#define _tmp_70_type 1338
+#define _loop0_71_type 1339
+#define _loop0_72_type 1340
+#define _loop1_73_type 1341
+#define _loop1_74_type 1342
+#define _loop0_75_type 1343
+#define _loop1_76_type 1344
+#define _loop0_77_type 1345
+#define _loop0_78_type 1346
+#define _loop0_79_type 1347
+#define _loop0_80_type 1348
+#define _loop1_81_type 1349
+#define _loop1_82_type 1350
+#define _tmp_83_type 1351
+#define _loop0_84_type 1352
+#define _gather_85_type 1353
+#define _loop1_86_type 1354
+#define _loop0_87_type 1355
+#define _tmp_88_type 1356
+#define _loop0_89_type 1357
+#define _gather_90_type 1358
+#define _tmp_91_type 1359
+#define _loop0_92_type 1360
+#define _gather_93_type 1361
+#define _loop0_94_type 1362
+#define _gather_95_type 1363
+#define _loop0_96_type 1364
+#define _loop0_97_type 1365
+#define _gather_98_type 1366
+#define _loop1_99_type 1367
+#define _tmp_100_type 1368
+#define _loop0_101_type 1369
+#define _gather_102_type 1370
+#define _loop0_103_type 1371
+#define _gather_104_type 1372
+#define _tmp_105_type 1373
+#define _tmp_106_type 1374
+#define _loop0_107_type 1375
+#define _gather_108_type 1376
+#define _tmp_109_type 1377
+#define _tmp_110_type 1378
+#define _tmp_111_type 1379
+#define _tmp_112_type 1380
+#define _tmp_113_type 1381
+#define _loop1_114_type 1382
+#define _tmp_115_type 1383
+#define _tmp_116_type 1384
+#define _tmp_117_type 1385
+#define _tmp_118_type 1386
+#define _tmp_119_type 1387
+#define _loop0_120_type 1388
+#define _loop0_121_type 1389
+#define _tmp_122_type 1390
+#define _tmp_123_type 1391
+#define _tmp_124_type 1392
+#define _tmp_125_type 1393
+#define _tmp_126_type 1394
+#define _tmp_127_type 1395
+#define _tmp_128_type 1396
+#define _tmp_129_type 1397
+#define _tmp_130_type 1398
+#define _loop0_131_type 1399
+#define _gather_132_type 1400
+#define _tmp_133_type 1401
+#define _tmp_134_type 1402
+#define _tmp_135_type 1403
+#define _tmp_136_type 1404
+#define _loop0_137_type 1405
+#define _gather_138_type 1406
+#define _tmp_139_type 1407
+#define _loop0_140_type 1408
+#define _gather_141_type 1409
+#define _loop0_142_type 1410
+#define _gather_143_type 1411
+#define _tmp_144_type 1412
+#define _loop0_145_type 1413
+#define _tmp_146_type 1414
+#define _tmp_147_type 1415
+#define _tmp_148_type 1416
+#define _tmp_149_type 1417
+#define _tmp_150_type 1418
+#define _tmp_151_type 1419
+#define _tmp_152_type 1420
+#define _tmp_153_type 1421
+#define _tmp_154_type 1422
+#define _tmp_155_type 1423
+#define _tmp_156_type 1424
+#define _tmp_157_type 1425
+#define _tmp_158_type 1426
+#define _tmp_159_type 1427
+#define _tmp_160_type 1428
+#define _tmp_161_type 1429
+#define _tmp_162_type 1430
+#define _tmp_163_type 1431
+#define _tmp_164_type 1432
+#define _tmp_165_type 1433
+#define _tmp_166_type 1434
+#define _tmp_167_type 1435
+#define _tmp_168_type 1436
+#define _tmp_169_type 1437
+#define _tmp_170_type 1438
+#define _tmp_171_type 1439
+#define _loop0_172_type 1440
+#define _tmp_173_type 1441
+#define _tmp_174_type 1442
+#define _tmp_175_type 1443
+#define _tmp_176_type 1444
+#define _tmp_177_type 1445
 
 static mod_ty file_rule(Parser *p);
 static mod_ty interactive_rule(Parser *p);
@@ -798,6 +799,7 @@ static void *invalid_string_tstring_concat_rule(Parser *p);
 static void *invalid_arithmetic_rule(Parser *p);
 static void *invalid_factor_rule(Parser *p);
 static void *invalid_type_params_rule(Parser *p);
+static void *invalid_noteq_rule(Parser *p);
 static asdl_seq *_loop0_1_rule(Parser *p);
 static asdl_seq *_loop1_2_rule(Parser *p);
 static asdl_seq *_loop0_3_rule(Parser *p);
@@ -12437,6 +12439,7 @@ comparison_rule(Parser *p)
 //     | eq_bitwise_or
 //     | noteq_bitwise_or
 //     | lte_bitwise_or
+//     | invalid_noteq
 //     | lt_bitwise_or
 //     | gte_bitwise_or
 //     | gt_bitwise_or
@@ -12513,6 +12516,25 @@ compare_op_bitwise_or_pair_rule(Parser *p)
         D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s 
failed!\n", p->level, ' ',
                   p->error_indicator ? "ERROR!" : "-", _mark, p->mark, 
"lte_bitwise_or"));
     }
+    if (p->call_invalid_rules) { // invalid_noteq
+        if (p->error_indicator) {
+            p->level--;
+            return NULL;
+        }
+        D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", 
p->level, ' ', _mark, p->mark, "invalid_noteq"));
+        void *invalid_noteq_var;
+        if (
+            (invalid_noteq_var = invalid_noteq_rule(p))  // invalid_noteq
+        )
+        {
+            D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s 
succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_noteq"));
+            _res = invalid_noteq_var;
+            goto done;
+        }
+        p->mark = _mark;
+        D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s 
failed!\n", p->level, ' ',
+                  p->error_indicator ? "ERROR!" : "-", _mark, p->mark, 
"invalid_noteq"));
+    }
     { // lt_bitwise_or
         if (p->error_indicator) {
             p->level--;
@@ -27265,6 +27287,52 @@ invalid_type_params_rule(Parser *p)
     return _res;
 }
 
+// invalid_noteq: '<' '>'
+static void *
+invalid_noteq_rule(Parser *p)
+{
+    if (p->level++ == MAXSTACK || 
_Py_ReachedRecursionLimitWithMargin(PyThreadState_Get(), 1)) {
+        _Pypegen_stack_overflow(p);
+    }
+    if (p->error_indicator) {
+        p->level--;
+        return NULL;
+    }
+    void * _res = NULL;
+    int _mark = p->mark;
+    { // '<' '>'
+        if (p->error_indicator) {
+            p->level--;
+            return NULL;
+        }
+        D(fprintf(stderr, "%*c> invalid_noteq[%d-%d]: %s\n", p->level, ' ', 
_mark, p->mark, "'<' '>'"));
+        Token * a;
+        Token * b;
+        if (
+            (a = _PyPegen_expect_token(p, 20))  // token='<'
+            &&
+            (b = _PyPegen_expect_token(p, 21))  // token='>'
+        )
+        {
+            D(fprintf(stderr, "%*c+ invalid_noteq[%d-%d]: %s succeeded!\n", 
p->level, ' ', _mark, p->mark, "'<' '>'"));
+            _res = _PyPegen_tokens_are_adjacent ( a , b ) ? 
RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , b , "invalid syntax.  Maybe you meant '!=' 
instead of '<>'?" ) : NULL;
+            if ((_res == NULL || p->error_indicator) && PyErr_Occurred()) {
+                p->error_indicator = 1;
+                p->level--;
+                return NULL;
+            }
+            goto done;
+        }
+        p->mark = _mark;
+        D(fprintf(stderr, "%*c%s invalid_noteq[%d-%d]: %s failed!\n", 
p->level, ' ',
+                  p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'<' 
'>'"));
+    }
+    _res = NULL;
+  done:
+    p->level--;
+    return _res;
+}
+
 // _loop0_1: NEWLINE
 static asdl_seq *
 _loop0_1_rule(Parser *p)
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 608adf3694117a..1dc039fccfa249 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1005,6 +1005,7 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int 
start_rule, PyObject *filena
                              PyCompilerFlags *flags, int *errcode,
                              PyObject **interactive_src, PyArena *arena)
 {
+    int parser_flags = compute_parser_flags(flags);
     struct tok_state *tok = _PyTokenizer_FromFile(fp, enc, ps1, ps2);
     if (tok == NULL) {
         if (PyErr_Occurred()) {
@@ -1016,6 +1017,7 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int 
start_rule, PyObject *filena
         }
         return NULL;
     }
+    tok->barry_as_bdfl = parser_flags & PyPARSE_BARRY_AS_BDFL;
     if (!tok->fp || ps1 != NULL || ps2 != NULL ||
         PyUnicode_CompareWithASCIIString(filename_ob, "<stdin>") == 0) {
         tok->fp_interactive = 1;
@@ -1026,7 +1028,6 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int 
start_rule, PyObject *filena
     // From here on we need to clean up even if there's an error
     mod_ty result = NULL;
 
-    int parser_flags = compute_parser_flags(flags);
     Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, 
PY_MINOR_VERSION,
                                     errcode, NULL, arena);
     if (p == NULL) {
@@ -1055,6 +1056,7 @@ _PyPegen_run_parser_from_string(const char *str, int 
start_rule, PyObject *filen
                        PyCompilerFlags *flags, PyArena *arena)
 {
     int exec_input = start_rule == Py_file_input;
+    int parser_flags = compute_parser_flags(flags);
 
     struct tok_state *tok;
     if (flags != NULL && flags->cf_flags & PyCF_IGNORE_COOKIE) {
@@ -1072,13 +1074,13 @@ _PyPegen_run_parser_from_string(const char *str, int 
start_rule, PyObject *filen
         }
         return NULL;
     }
+    tok->barry_as_bdfl = parser_flags & PyPARSE_BARRY_AS_BDFL;
     // This transfers the ownership to the tokenizer
     tok->filename = Py_NewRef(filename_ob);
 
     // We need to clear up from here on
     mod_ty result = NULL;
 
-    int parser_flags = compute_parser_flags(flags);
     int feature_version = flags && (flags->cf_flags & PyCF_ONLY_AST) ?
         flags->cf_feature_version : PY_MINOR_VERSION;
     Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, 
feature_version,
diff --git a/Parser/pegen.h b/Parser/pegen.h
index 1330d08bd6a10a..56d5d1b3bc8bde 100644
--- a/Parser/pegen.h
+++ b/Parser/pegen.h
@@ -209,6 +209,12 @@ RAISE_ERROR_KNOWN_LOCATION(Parser *p, PyObject *errtype,
     RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, (a)->lineno, 
(a)->col_offset, CURRENT_POS, CURRENT_POS, msg, ##__VA_ARGS__)
 #define RAISE_SYNTAX_ERROR_INVALID_TARGET(type, e) 
_RAISE_SYNTAX_ERROR_INVALID_TARGET(p, type, e)
 
+Py_LOCAL_INLINE(int)
+_PyPegen_tokens_are_adjacent(Token *a, Token *b)
+{
+    return (a->end_lineno == b->lineno) && (a->end_col_offset == 
b->col_offset);
+}
+
 Py_LOCAL_INLINE(void *)
 CHECK_CALL(Parser *p, void *result)
 {

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to