diff --git a/pycparserext/ext_c_generator.py b/pycparserext/ext_c_generator.py index a2bc88d..dc958e3 100644 --- a/pycparserext/ext_c_generator.py +++ b/pycparserext/ext_c_generator.py @@ -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, @@ -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) diff --git a/pycparserext/ext_c_lexer.py b/pycparserext/ext_c_lexer.py index 638d92a..e0c4edb 100644 --- a/pycparserext/ext_c_lexer.py +++ b/pycparserext/ext_c_lexer.py @@ -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=" @@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs): class OpenCLCLexer(CLexerBase): - tokens = CLexerBase.tokens + ("LINECOMMENT",) + tokens = (*CLexerBase.tokens, "LINECOMMENT") states = ( # ('comment', 'exclusive'), # ('preproc', 'exclusive'), @@ -40,12 +40,12 @@ class OpenCLCLexer(CLexerBase): ("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 diff --git a/pycparserext/ext_c_parser.py b/pycparserext/ext_c_parser.py index 26de7bc..71e7d47 100644 --- a/pycparserext/ext_c_parser.py +++ b/pycparserext/ext_c_parser.py @@ -1,4 +1,3 @@ -from __future__ import division import pycparser.c_ast as c_ast import pycparser.c_parser @@ -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 = () @@ -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 """ @@ -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 """ @@ -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 @@ -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) diff --git a/test/test_pycparserext.py b/test/test_pycparserext.py index 627d766..837543a 100644 --- a/test/test_pycparserext.py +++ b/test/test_pycparserext.py @@ -1,4 +1,3 @@ -from __future__ import print_function import pytest