From 65e323c4b4a1400da4e974908f23da28b943c032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Gl=C3=A4=C3=9Fle?= Date: Sat, 28 Dec 2024 02:15:13 +0100 Subject: [PATCH] Fix two linter issues, no longer ignore rule --- pyproject.toml | 6 +----- src/cpymad/util.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 94809f0c..9526bb39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,11 +81,7 @@ paths.source = [ [tool.ruff] line-length = 84 -lint.ignore = [ - "E701", - "E731", - "E741", -] +lint.per-file-ignores = {"src/cpymad/util.py" = ["E701"]} exclude = [ ".git", "__pycache__", diff --git a/src/cpymad/util.py b/src/cpymad/util.py index 97867b24..eb8c9cdd 100644 --- a/src/cpymad/util.py +++ b/src/cpymad/util.py @@ -63,7 +63,10 @@ def _fix_name(name: str) -> str: # precompile regexes for performance: -re_compile = lambda s: re.compile(s, re.IGNORECASE) +def re_compile(s): + return re.compile(s, re.IGNORECASE) + + _re_is_identifier = re_compile(r'^[a-z_][a-z0-9_]*$') _re_symbol = re_compile(r'([a-z_][a-z0-9._]*(->[a-z_][a-z0-9._]*(\[[0-9]+\])?)?)') _re_element_internal = re_compile(r'^([a-z_][a-z0-9_.$]*)(:\d+)?$') @@ -448,10 +451,10 @@ def tokenize(tokens, expr: str): stop = len(expr) while i < stop: for toktype, tokmatch in tokens: - l = tokmatch(expr, i) - if l > 0: - yield Token(toktype, i, l, expr) - i += l + length = tokmatch(expr, i) + if length > 0: + yield Token(toktype, i, length, expr) + i += length break else: raise ValueError("Unknown token {!r} at {!r}"