Skip to content

Commit b2d9489

Browse files
committed
linting
1 parent 60bd662 commit b2d9489

6 files changed

Lines changed: 64 additions & 52 deletions

File tree

src/xulbux/console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .color import Color, hexa
1212
from .regex import LazyRegex
1313

14-
from typing import Generator, Callable, Optional, Literal, Mapping, TypeVar, TextIO, cast
14+
from typing import Generator, Callable, Optional, Literal, TypeVar, TextIO, cast
1515
from prompt_toolkit.key_binding import KeyPressEvent, KeyBindings
1616
from prompt_toolkit.validation import ValidationError, Validator
1717
from prompt_toolkit.styles import Style

src/xulbux/data.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def remove_comments(
200200
raise ValueError("The 'comment_start' parameter string must not be empty.")
201201

202202
pattern = _re.compile(Regex._clean( \
203-
rf"""^(
203+
rf"""^(
204204
(?:(?!{_re.escape(comment_start)}).)*
205205
)
206206
{_re.escape(comment_start)}
@@ -566,19 +566,15 @@ def should_expand(seq: IndexIterable) -> bool:
566566
complex_types = (list, tuple, dict, set, frozenset) + ((bytes, bytearray) if as_json else ())
567567
complex_items = sum(1 for item in seq if isinstance(item, complex_types))
568568

569-
return (
570-
complex_items > 1 or (complex_items == 1 and len(seq) > 1) or Data.chars_count(seq) +
571-
(len(seq) * len(sep)) > max_width
572-
)
569+
return complex_items > 1 \
570+
or (complex_items == 1 and len(seq) > 1) \
571+
or Data.chars_count(seq) + (len(seq) * len(sep)) > max_width
573572

574573
def format_dict(d: dict, current_indent: int) -> str:
575574
if compactness == 2 or not d or not should_expand(list(d.values())):
576-
return punct["{"] \
577-
+ sep.join(
578-
f"{format_value(k)}{punct[':']} {format_value(v, current_indent)}"
579-
for k, v in d.items()
580-
) \
581-
+ punct["}"]
575+
return punct["{"] + sep.join(
576+
f"{format_value(k)}{punct[':']} {format_value(v, current_indent)}" for k, v in d.items()
577+
) + punct["}"]
582578

583579
items = []
584580
for k, val in d.items():

src/xulbux/env_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __persistent(path: str, remove: bool = False) -> None:
8989
_winreg.SetValueEx(key, "PATH", 0, _winreg.REG_EXPAND_SZ, new_path)
9090
_winreg.CloseKey(key)
9191
except Exception as e:
92-
raise RuntimeError(f"Failed to update PATH in registry:\n " + str(e).replace("\n", " \n"))
92+
raise RuntimeError("Failed to update PATH in registry:\n " + str(e).replace("\n", " \n"))
9393

9494
else: # UNIX-LIKE (LINUX/macOS)
9595
shell_rc_file = _os.path.expanduser(

src/xulbux/format_codes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,10 @@ def replace_keys(match: Match) -> str:
367367
else:
368368
ansi_resets = []
369369

370-
if not (len(ansi_formats) == 1 and ansi_formats[0].count(f"{ANSI.CHAR}{ANSI.START}") >= 1) and \
371-
not all(f.startswith(f"{ANSI.CHAR}{ANSI.START}") for f in ansi_formats): # FORMATTING WAS INVALID
370+
if (
371+
not (len(ansi_formats) == 1 and ansi_formats[0].count(f"{ANSI.CHAR}{ANSI.START}") >= 1) and \
372+
not all(f.startswith(f"{ANSI.CHAR}{ANSI.START}") for f in ansi_formats) # FORMATTING WAS INVALID
373+
):
372374
return match.group(0)
373375
elif formats_escaped: # FORMATTING WAS VALID BUT ESCAPED
374376
return f"[{_formats}]({auto_reset_txt})" if auto_reset_txt else f"[{_formats}]"

src/xulbux/regex.py

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,28 @@ def brackets(
4747
s2 = "" if strip_spaces else r"\s*"
4848

4949
if ignore_in_strings:
50-
return Regex._clean(
50+
return Regex._clean( \
5151
rf"""{b1}{s1}({g}{s2}(?:
52-
[^{b1}{b2}"']
53-
|"(?:\\.|[^"\\])*"
54-
|'(?:\\.|[^'\\])*'
55-
|{b1}(?:
5652
[^{b1}{b2}"']
5753
|"(?:\\.|[^"\\])*"
5854
|'(?:\\.|[^'\\])*'
59-
|(?R)
60-
)*{b2}
61-
)*{s2}){s1}{b2}"""
55+
|{b1}(?:
56+
[^{b1}{b2}"']
57+
|"(?:\\.|[^"\\])*"
58+
|'(?:\\.|[^'\\])*'
59+
|(?R)
60+
)*{b2}
61+
)*{s2}){s1}{b2}"""
6262
)
6363
else:
64-
return Regex._clean(
64+
return Regex._clean( \
6565
rf"""{b1}{s1}({g}{s2}(?:
66-
[^{b1}{b2}]
67-
|{b1}(?:
6866
[^{b1}{b2}]
69-
|(?R)
70-
)*{b2}
71-
)*{s2}){s1}{b2}"""
67+
|{b1}(?:
68+
[^{b1}{b2}]
69+
|(?R)
70+
)*{b2}
71+
)*{s2}){s1}{b2}"""
7272
)
7373

7474
@staticmethod
@@ -89,11 +89,11 @@ def all_except(disallowed_pattern: str, ignore_pattern: str = "", is_group: bool
8989
- `is_group` -⠀whether to create a capturing group for the matched content"""
9090
g = "" if is_group else "?:"
9191

92-
return Regex._clean(
92+
return Regex._clean( \
9393
rf"""({g}
94-
(?:(?!{ignore_pattern}).)*
95-
(?:(?!{Regex.outside_strings(disallowed_pattern)}).)*
96-
)"""
94+
(?:(?!{ignore_pattern}).)*
95+
(?:(?!{Regex.outside_strings(disallowed_pattern)}).)*
96+
)"""
9797
)
9898

9999
@staticmethod
@@ -136,14 +136,20 @@ def rgba_str(fix_sep: Optional[str] = ",", allow_alpha: bool = True) -> str:
136136
(?:\s*{fix_sep}\s*)((?:0*(?:25[0-5]|2[0-4][0-9]|1?[0-9]{{1,2}})))
137137
(?:\s*{fix_sep}\s*)((?:0*(?:25[0-5]|2[0-4][0-9]|1?[0-9]{{1,2}})))"""
138138

139-
return Regex._clean(rf"""(?ix)(?:rgb|rgba)?\s*(?:
140-
\(?\s*{rgb_part}
141-
(?:(?:\s*{fix_sep}\s*)((?:0*(?:0?\.[0-9]+|1\.0+|[0-9]+\.[0-9]+|[0-9]+))))?
142-
\s*\)?
143-
)""" if allow_alpha else \
144-
rf"""(?ix)(?:rgb|rgba)?\s*(?:
145-
\(?\s*{rgb_part}\s*\)?
146-
)""")
139+
if allow_alpha:
140+
return Regex._clean( \
141+
rf"""(?ix)(?:rgb|rgba)?\s*(?:
142+
\(?\s*{rgb_part}
143+
(?:(?:\s*{fix_sep}\s*)((?:0*(?:0?\.[0-9]+|1\.0+|[0-9]+\.[0-9]+|[0-9]+))))?
144+
\s*\)?
145+
)"""
146+
)
147+
else:
148+
return Regex._clean( \
149+
rf"""(?ix)(?:rgb|rgba)?\s*(?:
150+
\(?\s*{rgb_part}\s*\)?
151+
)"""
152+
)
147153

148154
@staticmethod
149155
def hsla_str(fix_sep: str = ",", allow_alpha: bool = True) -> str:
@@ -172,14 +178,20 @@ def hsla_str(fix_sep: str = ",", allow_alpha: bool = True) -> str:
172178
(?:\s*{fix_sep}\s*)((?:0*(?:100|[1-9][0-9]|[0-9])))(?:\s*%)?
173179
(?:\s*{fix_sep}\s*)((?:0*(?:100|[1-9][0-9]|[0-9])))(?:\s*%)?"""
174180

175-
return Regex._clean(rf"""(?ix)(?:hsl|hsla)?\s*(?:
176-
\(?\s*{hsl_part}
177-
(?:(?:\s*{fix_sep}\s*)((?:0*(?:0?\.[0-9]+|1\.0+|[0-9]+\.[0-9]+|[0-9]+))))?
178-
\s*\)?
179-
)""" if allow_alpha else \
180-
rf"""(?ix)(?:hsl|hsla)?\s*(?:
181-
\(?\s*{hsl_part}\s*\)?
182-
)""")
181+
if allow_alpha:
182+
return Regex._clean( \
183+
rf"""(?ix)(?:hsl|hsla)?\s*(?:
184+
\(?\s*{hsl_part}
185+
(?:(?:\s*{fix_sep}\s*)((?:0*(?:0?\.[0-9]+|1\.0+|[0-9]+\.[0-9]+|[0-9]+))))?
186+
\s*\)?
187+
)"""
188+
)
189+
else:
190+
return Regex._clean( \
191+
rf"""(?ix)(?:hsl|hsla)?\s*(?:
192+
\(?\s*{hsl_part}\s*\)?
193+
)"""
194+
)
183195

184196
@staticmethod
185197
def hexa_str(allow_alpha: bool = True) -> str:

tests/test_console.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,9 +1233,11 @@ def test_spinner_context_manager():
12331233

12341234
def test_spinner_context_manager_exception():
12351235
spinner = Spinner()
1236-
with patch.object(spinner, "start"), patch.object(spinner, "stop") as mock_stop, \
1237-
patch.object(spinner, "_emergency_cleanup") as mock_cleanup:
1238-
1236+
with ( \
1237+
patch.object(spinner, "start"),
1238+
patch.object(spinner, "stop") as mock_stop,
1239+
patch.object(spinner, "_emergency_cleanup") as mock_cleanup
1240+
):
12391241
with pytest.raises(ValueError):
12401242
with spinner.context("Test"):
12411243
raise ValueError("Oops")

0 commit comments

Comments
 (0)