Skip to content

Commit 2159db8

Browse files
committed
remove unused imports and rename FormatCodes.__config_console() to _config_console()
1 parent 17809d1 commit 2159db8

6 files changed

Lines changed: 11 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Added a new class `LazyRegex` to the `regex` module, which is used to define regex patterns that are only compiled when they are used for the first time.
2222
* Removed unnecessary character escaping in the precompiled regex patterns in the `console` module.
2323
* Removed all the runtime type-checks that can also be checked using static type-checking tools, since you're supposed to use type checkers in modern python anyway, and to improve performance.
24+
* Renamed the internal class method `FormatCodes.__config_console()` to `FormatCodes._config_console()` to make it callable, but still indicate that it's internal.
2425

2526
**BREAKING CHANGES:**
2627
* Replaced the internal `_COMPILED` regex pattern dictionaries with `LazyRegex` objects so it won't compile all regex patterns on library import, but only when they are used for the first time, which improves the library's import time.

src/xulbux/cli/help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ def is_latest_version() -> Optional[bool]:
7272

7373

7474
def show_help() -> None:
75-
FormatCodes.__config_console()
75+
FormatCodes._config_console()
7676
print(CLI_HELP)
7777
Console.pause_exit(pause=True, prompt=" [dim](Press any key to exit...)\n\n")

src/xulbux/console.py

Lines changed: 2 additions & 3 deletions
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, Pattern, TypeVar, TextIO, cast
14+
from typing import Generator, Callable, Optional, Literal, Mapping, 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
@@ -25,10 +25,9 @@
2525
import time as _time
2626
import sys as _sys
2727
import os as _os
28-
import re as _re
2928
import io as _io
3029

31-
# PRECOMPILE REGULAR EXPRESSIONS
30+
3231
_PATTERNS = LazyRegex(
3332
hr=r"(?i){hr}",
3433
hr_no_nl=r"(?i)(?<!\n){hr}(?!\n)",

src/xulbux/format_codes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def print(
230230
--------------------------------------------------------------------------------------------------
231231
For exact information about how to use special formatting codes,
232232
see the `format_codes` module documentation."""
233-
FormatCodes.__config_console()
233+
FormatCodes._config_console()
234234
_sys.stdout.write(FormatCodes.to_ansi(sep.join(map(str, values)) + end, default_color, brightness_steps))
235235

236236
if flush:
@@ -253,7 +253,7 @@ def input(
253253
--------------------------------------------------------------------------------------------------
254254
For exact information about how to use special formatting codes, see the
255255
`format_codes` module documentation."""
256-
FormatCodes.__config_console()
256+
FormatCodes._config_console()
257257
user_input = input(FormatCodes.to_ansi(str(prompt), default_color, brightness_steps))
258258

259259
if reset_ansi:
@@ -497,8 +497,10 @@ def replacement(match: Match) -> str:
497497
return _PATTERNS.ansi_seq.sub("", ansi_string)
498498

499499
@staticmethod
500-
def __config_console() -> None:
501-
"""Configure the console to be able to interpret and render ANSI formatting."""
500+
def _config_console() -> None:
501+
"""Internal method which configure the console to be able to interpret and render ANSI formatting.\n
502+
-----------------------------------------------------------------------------------------------------
503+
This method will only do something the first time it's called. Subsequent calls will do nothing."""
502504
global _CONSOLE_ANSI_CONFIGURED
503505
if not _CONSOLE_ANSI_CONFIGURED:
504506
_sys.stdout.flush()

src/xulbux/regex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def hexa_str(allow_alpha: bool = True) -> str:
196196

197197
@staticmethod
198198
def _clean(pattern: str) -> str:
199-
"""Internal method, to make a multiline-string regex pattern into a single-line pattern."""
199+
"""Internal method to make a multiline-string regex pattern into a single-line pattern."""
200200
return "".join(l.strip() for l in pattern.splitlines()).strip()
201201

202202

tests/test_console.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from collections import namedtuple
66
import builtins
77
import pytest
8-
import time
98
import sys
109
import io
1110

0 commit comments

Comments
 (0)