Skip to content

Commit

Permalink
Additional ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Nov 26, 2024
1 parent 872fe19 commit c7ee565
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pycparserext/ext_c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def visit_UnaryOp(self, n):
return "%s %s" % (n.op, operand)


class AsmAndAttributesMixin(object):
class AsmAndAttributesMixin:
def visit_Asm(self, n):
components = [
n.template,
Expand Down Expand Up @@ -120,7 +120,7 @@ def _generate_type(self, n, modifiers=None, emit_declname=True):

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

else:
return self.visit(n)
Expand Down
8 changes: 4 additions & 4 deletions pycparserext/ext_c_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GnuCLexer(CLexerBase):
+ CLexerBase.exponent_part+"))i?[FfLl]?)")

@TOKEN(floating_constant)
def t_FLOAT_CONST(self, t): # noqa: N802
def t_FLOAT_CONST(self, t):
return t

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


class OpenCLCLexer(CLexerBase):
tokens = CLexerBase.tokens + ("LINECOMMENT",)
tokens = (*CLexerBase.tokens, "LINECOMMENT")
states = (
# ('comment', 'exclusive'),
# ('preproc', 'exclusive'),
("ppline", "exclusive"), # unused
("pppragma", "exclusive"), # unused
)

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

# overrides pycparser, must have same name
def t_PPHASH(self, t): # noqa: N802
def t_PPHASH(self, t):
r"[ \t]*\#([^\n]|\\\n)+[^\n\\]\n"
t.lexer.lineno += t.value.count("\n")
return t
Expand Down
12 changes: 5 additions & 7 deletions pycparserext/ext_c_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division

import pycparser.c_ast as c_ast
import pycparser.c_parser
Expand Down Expand Up @@ -51,8 +50,7 @@ def children(self):
return tuple(nodelist)

def __iter__(self):
for child in (self.types or []):
yield child
yield from (self.types or [])

attr_names = ()

Expand Down Expand Up @@ -260,7 +258,7 @@ def __iter__(self):

# {{{ attributes

class _AttributesMixin(object):
class _AttributesMixin:
def p_attributes_opt_1(self, p):
""" attributes_opt : attribute_decl attributes_opt
"""
Expand Down Expand Up @@ -309,7 +307,7 @@ def p_function_specifier_attr(self, p):

# {{{ asm

class _AsmMixin(object):
class _AsmMixin:
def p_asm_opt_1(self, p):
""" asm_opt : empty
"""
Expand Down Expand Up @@ -494,7 +492,7 @@ class GnuCParser(_AsmAndAttributesMixin, CParserBase):

from pycparserext.ext_c_lexer import GnuCLexer as lexer_class # noqa

initial_type_symbols = {"__builtin_va_list"}
initial_type_symbols = frozenset({"__builtin_va_list"})

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

INT_BIT_COUNTS = [8, 16, 32, 64]
INT_BIT_COUNTS = (8, 16, 32, 64)
initial_type_symbols = (
{
"%s%d" % (base_name, count)
Expand Down
1 change: 0 additions & 1 deletion test/test_pycparserext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function

import pytest

Expand Down

0 comments on commit c7ee565

Please sign in to comment.