Skip to content

Commit c7ee565

Browse files
committed
Additional ruff fixes
1 parent 872fe19 commit c7ee565

4 files changed

Lines changed: 11 additions & 14 deletions

File tree

pycparserext/ext_c_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def visit_UnaryOp(self, n):
2121
return "%s %s" % (n.op, operand)
2222

2323

24-
class AsmAndAttributesMixin(object):
24+
class AsmAndAttributesMixin:
2525
def visit_Asm(self, n):
2626
components = [
2727
n.template,
@@ -120,7 +120,7 @@ def _generate_type(self, n, modifiers=None, emit_declname=True):
120120

121121
elif typ in (c_ast.ArrayDecl, c_ast.PtrDecl, c_ast.FuncDecl, FuncDeclExt):
122122
return self._generate_type(
123-
n.type, modifiers + [n], emit_declname=emit_declname)
123+
n.type, [*modifiers, n], emit_declname=emit_declname)
124124

125125
else:
126126
return self.visit(n)

pycparserext/ext_c_lexer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GnuCLexer(CLexerBase):
1616
+ CLexerBase.exponent_part+"))i?[FfLl]?)")
1717

1818
@TOKEN(floating_constant)
19-
def t_FLOAT_CONST(self, t): # noqa: N802
19+
def t_FLOAT_CONST(self, t):
2020
return t
2121

2222
t_pppragma_ignore = " \t<>.-{}();+-*/$%@&^~!?:,0123456789="
@@ -32,20 +32,20 @@ def __init__(self, *args, **kwargs):
3232

3333

3434
class OpenCLCLexer(CLexerBase):
35-
tokens = CLexerBase.tokens + ("LINECOMMENT",)
35+
tokens = (*CLexerBase.tokens, "LINECOMMENT")
3636
states = (
3737
# ('comment', 'exclusive'),
3838
# ('preproc', 'exclusive'),
3939
("ppline", "exclusive"), # unused
4040
("pppragma", "exclusive"), # unused
4141
)
4242

43-
def t_LINECOMMENT(self, t): # noqa: N802
43+
def t_LINECOMMENT(self, t):
4444
r"\/\/([^\n]+)\n"
4545
t.lexer.lineno += t.value.count("\n")
4646

4747
# overrides pycparser, must have same name
48-
def t_PPHASH(self, t): # noqa: N802
48+
def t_PPHASH(self, t):
4949
r"[ \t]*\#([^\n]|\\\n)+[^\n\\]\n"
5050
t.lexer.lineno += t.value.count("\n")
5151
return t

pycparserext/ext_c_parser.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import division
21

32
import pycparser.c_ast as c_ast
43
import pycparser.c_parser
@@ -51,8 +50,7 @@ def children(self):
5150
return tuple(nodelist)
5251

5352
def __iter__(self):
54-
for child in (self.types or []):
55-
yield child
53+
yield from (self.types or [])
5654

5755
attr_names = ()
5856

@@ -260,7 +258,7 @@ def __iter__(self):
260258

261259
# {{{ attributes
262260

263-
class _AttributesMixin(object):
261+
class _AttributesMixin:
264262
def p_attributes_opt_1(self, p):
265263
""" attributes_opt : attribute_decl attributes_opt
266264
"""
@@ -309,7 +307,7 @@ def p_function_specifier_attr(self, p):
309307

310308
# {{{ asm
311309

312-
class _AsmMixin(object):
310+
class _AsmMixin:
313311
def p_asm_opt_1(self, p):
314312
""" asm_opt : empty
315313
"""
@@ -494,7 +492,7 @@ class GnuCParser(_AsmAndAttributesMixin, CParserBase):
494492

495493
from pycparserext.ext_c_lexer import GnuCLexer as lexer_class # noqa
496494

497-
initial_type_symbols = {"__builtin_va_list"}
495+
initial_type_symbols = frozenset({"__builtin_va_list"})
498496

499497
def p_function_specifier_gnu(self, p):
500498
""" function_specifier : __INLINE
@@ -600,7 +598,7 @@ def p_unified_volatile_gnu(self, p):
600598
class OpenCLCParser(_AsmAndAttributesMixin, CParserBase):
601599
from pycparserext.ext_c_lexer import OpenCLCLexer as lexer_class # noqa
602600

603-
INT_BIT_COUNTS = [8, 16, 32, 64]
601+
INT_BIT_COUNTS = (8, 16, 32, 64)
604602
initial_type_symbols = (
605603
{
606604
"%s%d" % (base_name, count)

test/test_pycparserext.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21

32
import pytest
43

0 commit comments

Comments
 (0)