| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -110,14 +110,6 @@ def check_dont_replace(self, source): | |||
| 110 | 110 | source = reformat(source) | |
| 111 | 111 | self.assertEqual(patch(source), source) | |
| 112 | 112 | ||
| 113 | - def test_expr_regex(self): | ||
| 114 | - self.check_replace("a->b->ob_type", "Py_TYPE(a->b)") | ||
| 115 | - self.check_replace("a.b->ob_type", "Py_TYPE(a.b)") | ||
| 116 | - self.check_replace("array[2]->ob_type", "Py_TYPE(array[2])") | ||
| 117 | - | ||
| 118 | - # Don't match function calls | ||
| 119 | - self.check_dont_replace("func()->ob_type") | ||
| 120 | - | ||
| 121 | 113 | def test_pythoncapi_compat(self): | |
| 122 | 114 | # If pythoncapi_compat.h is included, avoid compatibility includes | |
| 123 | 115 | # and macros. | |
@@ -538,6 +530,32 @@ def test_py_is(self): | |||
| 538 | 530 | } | |
| 539 | 531 | """) | |
| 540 | 532 | ||
| 533 | + self.check_replace(""" | ||
| 534 | + void test_expr(struct MyStruct *obj) | ||
| 535 | + { | ||
| 536 | + if (obj->attr1 == Py_None) { | ||
| 537 | + return 1; | ||
| 538 | + } | ||
| 539 | + if (obj->attr2.name == Py_None) { | ||
| 540 | + return 1; | ||
| 541 | + } | ||
| 542 | + return 0; | ||
| 543 | + } | ||
| 544 | + """, """ | ||
| 545 | + #include "pythoncapi_compat.h" | ||
| 546 | + | ||
| 547 | + void test_expr(struct MyStruct *obj) | ||
| 548 | + { | ||
| 549 | + if (Py_IsNone(obj->attr1)) { | ||
| 550 | + return 1; | ||
| 551 | + } | ||
| 552 | + if (Py_IsNone(obj->attr2.name)) { | ||
| 553 | + return 1; | ||
| 554 | + } | ||
| 555 | + return 0; | ||
| 556 | + } | ||
| 557 | + """) | ||
| 558 | + | ||
| 541 | 559 | ||
| 542 | 560 | def test_no_compat(self): | |
| 543 | 561 | # Don't add "#include "pythoncapi_compat.h" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -315,12 +315,12 @@ def replace2(regs): | |||
| 315 | 315 | return f'{x} = _Py_StealRef({y});' | |
| 316 | 316 | ||
| 317 | 317 | REPLACE = [] | |
| 318 | - id_regex = r'(%s)' % ID_REGEX | ||
| 318 | + expr = r'(%s)' % EXPR_REGEX | ||
| 319 | 319 | for name in ('None', 'True', 'False'): | |
| 320 | 320 | REPLACE.extend(( | |
| 321 | - (re.compile(fr'({ID_REGEX}) == Py_{name}\b'), | ||
| 321 | + (re.compile(fr'{expr} == Py_{name}\b'), | ||
| 322 | 322 | fr'Py_Is{name}(\1)'), | |
| 323 | - (re.compile(fr'({ID_REGEX}) != Py_{name}\b'), | ||
| 323 | + (re.compile(fr'{expr} != Py_{name}\b'), | ||
| 324 | 324 | fr'!Py_Is{name}(\1)'), | |
| 325 | 325 | )) | |
| 326 | 326 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments