From b559529433492c03dda06becbf37b23a044cbdf3 Mon Sep 17 00:00:00 2001 From: seladb Date: Tue, 3 Oct 2023 21:19:02 -0700 Subject: [PATCH] Various fixes after running `pylint` --- cxxheaderparser/_ply/lex.py | 6 +++--- cxxheaderparser/gentest.py | 12 ++++++------ cxxheaderparser/lexer.py | 7 ++----- cxxheaderparser/parser.py | 7 ++++--- cxxheaderparser/preprocessor.py | 1 - cxxheaderparser/simple.py | 1 - 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cxxheaderparser/_ply/lex.py b/cxxheaderparser/_ply/lex.py index 766a917..7e3679b 100644 --- a/cxxheaderparser/_ply/lex.py +++ b/cxxheaderparser/_ply/lex.py @@ -233,9 +233,9 @@ def token(self): if tok.type: self.lexpos = m.end() return tok - else: - lexpos = m.end() - break + + lexpos = m.end() + break lexpos = m.end() diff --git a/cxxheaderparser/gentest.py b/cxxheaderparser/gentest.py index a738298..46af4ab 100644 --- a/cxxheaderparser/gentest.py +++ b/cxxheaderparser/gentest.py @@ -1,7 +1,6 @@ import argparse import dataclasses import inspect -import re import subprocess import typing @@ -37,15 +36,16 @@ def _inner_repr(o: typing.Any) -> str: return f"{o.__class__.__qualname__ }({', '.join(vals)})" - elif isinstance(o, list): + if isinstance(o, list): return f"[{','.join(_inner_repr(l) for l in o)}]" - elif isinstance(o, dict): + + if isinstance(o, dict): vals = [] for k, v in o.items(): vals.append(f'"{k}": {_inner_repr(v)}') return "{" + ",".join(vals) + "}" - else: - return repr(o) + + return repr(o) return _inner_repr(data) @@ -72,7 +72,7 @@ def gentest( data = parse_string(content, options=options) if fail: raise ValueError("did not fail") - except CxxParseError as e: + except CxxParseError: if not fail: raise # do it again, but strip the content so the error message matches diff --git a/cxxheaderparser/lexer.py b/cxxheaderparser/lexer.py index b62e660..2a6bf26 100644 --- a/cxxheaderparser/lexer.py +++ b/cxxheaderparser/lexer.py @@ -1,5 +1,3 @@ -import contextlib -from collections import deque import re import typing import sys @@ -782,7 +780,8 @@ def get_doxygen_after(self) -> typing.Optional[str]: tok = tokbuf.popleft() if tok.type == "NEWLINE": break - elif tok.type == "WHITESPACE": + + if tok.type == "WHITESPACE": new_tokbuf.append(tok) elif tok.type in ("COMMENT_SINGLELINE", "COMMENT_MULTILINE"): comments.append(tok) @@ -838,8 +837,6 @@ def has_tokens(self) -> bool: return len(self.tokbuf) > 0 def _fill_tokbuf(self, tokbuf: typing.Deque[LexToken]) -> bool: - from .errors import CxxParseError - raise CxxParseError("no more tokens left in this group") def current_location(self) -> Location: diff --git a/cxxheaderparser/parser.py b/cxxheaderparser/parser.py index 1b53429..b495cb0 100644 --- a/cxxheaderparser/parser.py +++ b/cxxheaderparser/parser.py @@ -94,7 +94,7 @@ def __init__( ) self.anon_id = 0 - self.verbose = True if self.options.verbose else False + self.verbose = self.options.verbose if self.verbose: def debug_print(fmt: str, *args: typing.Any) -> None: @@ -1755,7 +1755,7 @@ def _parse_method_end(self, method: Method) -> None: break - elif tok_value == "=": + if tok_value == "=": tok = get_token() tok_value = tok.value @@ -1769,7 +1769,8 @@ def _parse_method_end(self, method: Method) -> None: raise self._parse_error(tok, "0/delete/default") break - elif tok_value in ("const", "volatile", "override", "final"): + + if tok_value in ("const", "volatile", "override", "final"): setattr(method, tok_value, True) elif tok_value in ("&", "&&"): method.ref_qualifier = tok_value diff --git a/cxxheaderparser/preprocessor.py b/cxxheaderparser/preprocessor.py index 33382dd..33f7771 100644 --- a/cxxheaderparser/preprocessor.py +++ b/cxxheaderparser/preprocessor.py @@ -5,7 +5,6 @@ import io import re import os -from os.path import relpath import typing from .options import PreprocessorFunction diff --git a/cxxheaderparser/simple.py b/cxxheaderparser/simple.py index a707877..421666b 100644 --- a/cxxheaderparser/simple.py +++ b/cxxheaderparser/simple.py @@ -50,7 +50,6 @@ ) from .parserstate import ( - State, ClassBlockState, ExternBlockState, NamespaceBlockState,