Skip to content

Commit c9bd293

Browse files
committed
Various AI cleanups
1 parent 21feecf commit c9bd293

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
strategy:
2828
matrix:
29-
python-version: ['3.8', '3.9', '3.x']
29+
python-version: ['3.10', '3.12', '3.x']
3030
steps:
3131
- uses: actions/checkout@v6
3232
-

pycparserext/ext_c_lexer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
class GnuCLexer(CLexerBase):
5050
"""GNU C lexer that recognizes GNU-specific keywords."""
5151

52-
_extra_keywords = {**_COMMON_EXTRA_KEYWORDS, **_GNU_EXTRA_KEYWORDS}
52+
_extra_keywords = {**_COMMON_EXTRA_KEYWORDS, **_GNU_EXTRA_KEYWORDS} # noqa: RUF012
5353

5454
def token(self):
5555
tok = super().token()
@@ -72,7 +72,7 @@ class OpenCLCLexer(CLexerBase):
7272
"""OpenCL C lexer that recognizes OpenCL-specific keywords and line
7373
comments."""
7474

75-
_extra_keywords = {**_COMMON_EXTRA_KEYWORDS, **_OCL_EXTRA_KEYWORDS}
75+
_extra_keywords = {**_COMMON_EXTRA_KEYWORDS, **_OCL_EXTRA_KEYWORDS} # noqa: RUF012
7676

7777
def token(self):
7878
tok = super().token()

pycparserext/ext_c_parser.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
_STORAGE_CLASS,
77
_TYPE_QUALIFIER,
88
_TYPE_SPEC_SIMPLE,
9-
_TokenStream,
109
)
1110

1211

@@ -50,7 +49,8 @@ def _compare_ast_nodes(self, node1, node2):
5049
children2 = node2.children()
5150
if len(children1) != len(children2):
5251
return False
53-
for (name1, child1), (name2, child2) in zip(children1, children2):
52+
for (name1, child1), (name2, child2) in zip(
53+
children1, children2, strict=False):
5454
if name1 != name2:
5555
return False
5656
if not self._compare_ast_nodes(child1, child2):
@@ -542,14 +542,13 @@ def _parse_function_decl(self, base_decl):
542542
coord=base_decl.coord,
543543
)
544544

545-
if self._peek_type() == "LBRACE":
546-
if func.args is not None:
547-
for param in func.args.params:
548-
if isinstance(param, c_ast.EllipsisParam):
549-
break
550-
name = getattr(param, "name", None)
551-
if name:
552-
self._add_identifier(name, param.coord)
545+
if self._peek_type() == "LBRACE" and func.args is not None:
546+
for param in func.args.params:
547+
if isinstance(param, c_ast.EllipsisParam):
548+
break
549+
name = getattr(param, "name", None)
550+
if name:
551+
self._add_identifier(name, param.coord)
553552

554553
return func
555554

@@ -659,12 +658,12 @@ def _parse_struct_declaration(self):
659658
decl_type = c_ast.IdentifierType(node)
660659
self._expect("SEMI")
661660
return self._build_declarations(
662-
spec=spec, decls=[dict(decl=decl_type, init=None, bitsize=None)]
661+
spec=spec, decls=[{"decl": decl_type, "init": None, "bitsize": None}]
663662
)
664663

665664
self._expect("SEMI")
666665
return self._build_declarations(
667-
spec=spec, decls=[dict(decl=None, init=None, bitsize=None)]
666+
spec=spec, decls=[{"decl": None, "init": None, "bitsize": None}]
668667
)
669668

670669
# }}}
@@ -941,15 +940,15 @@ def _parse_specifier_qualifier_list(self):
941940

942941
def _parse_type_qualifier_list(self):
943942
quals = []
944-
_all_quals = _TYPE_QUALIFIER | _GNU_TYPE_QUALIFIERS
945-
while self._peek_type() in _all_quals:
943+
all_quals = _TYPE_QUALIFIER | _GNU_TYPE_QUALIFIERS
944+
while self._peek_type() in all_quals:
946945
quals.append(self._advance().value)
947946
return quals
948947

949948
def _parse_array_decl_common(self, base_type, coord=None):
950949
"""Override to handle GNU type qualifiers inside array dimensions."""
951950
from pycparser.c_parser import _TYPE_QUALIFIER
952-
_all_quals = _TYPE_QUALIFIER | _GNU_TYPE_QUALIFIERS
951+
all_quals = _TYPE_QUALIFIER | _GNU_TYPE_QUALIFIERS
953952

954953
lbrack_tok = self._expect("LBRACKET")
955954
if coord is None:
@@ -966,10 +965,10 @@ def make_array_decl(dim, dim_quals):
966965
self._expect("RBRACKET")
967966
return make_array_decl(dim, dim_quals)
968967

969-
if self._peek_type() in _all_quals:
968+
if self._peek_type() in all_quals:
970969
dim_quals = self._parse_type_qualifier_list() or []
971970
if self._accept("STATIC"):
972-
dim_quals = dim_quals + ["static"]
971+
dim_quals = [*dim_quals, "static"]
973972
dim = self._parse_assignment_expression()
974973
self._expect("RBRACKET")
975974
return make_array_decl(dim, dim_quals)
@@ -1355,8 +1354,8 @@ def _parse_specifier_qualifier_list(self):
13551354

13561355
def _parse_type_qualifier_list(self):
13571356
quals = []
1358-
_all_quals = _TYPE_QUALIFIER | _OCL_TYPE_QUALIFIERS
1359-
while self._peek_type() in _all_quals:
1357+
all_quals = _TYPE_QUALIFIER | _OCL_TYPE_QUALIFIERS
1358+
while self._peek_type() in all_quals:
13601359
quals.append(self._advance().value)
13611360
return quals
13621361

0 commit comments

Comments
 (0)