Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions Lib/_colorize.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import builtins
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just do from builtins import str as _str? it may be a bit easier to read then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could, but I kind of like the explicitness of the current solution. But if others agree I am happy to change it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also good with that. I just know that in other modules we also have _str = builtins.str or _int = builtins.int. I'll let Hugo decide (I just find the repetition of builtins.str a bit less readable but that's my opinion)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, if it is already a pattern elsewhere then I am more okay with that. Will wait for others to chime in before changing.

import os
import sys

Expand Down Expand Up @@ -202,25 +203,25 @@ class Difflib(ThemeSection):
@dataclass(frozen=True, kw_only=True)
class FancyCompleter(ThemeSection):
# functions and methods
function: str = ANSIColors.BOLD_BLUE
builtin_function_or_method: str = ANSIColors.BOLD_BLUE
method: str = ANSIColors.BOLD_CYAN
method_wrapper: str = ANSIColors.BOLD_CYAN
wrapper_descriptor: str = ANSIColors.BOLD_CYAN
method_descriptor: str = ANSIColors.BOLD_CYAN
function: builtins.str = ANSIColors.BOLD_BLUE
builtin_function_or_method: builtins.str = ANSIColors.BOLD_BLUE
method: builtins.str = ANSIColors.BOLD_CYAN
method_wrapper: builtins.str = ANSIColors.BOLD_CYAN
wrapper_descriptor: builtins.str = ANSIColors.BOLD_CYAN
method_descriptor: builtins.str = ANSIColors.BOLD_CYAN

# numbers
int: str = ANSIColors.BOLD_YELLOW
float: str = ANSIColors.BOLD_YELLOW
complex: str = ANSIColors.BOLD_YELLOW
bool: str = ANSIColors.BOLD_YELLOW
int: builtins.str = ANSIColors.BOLD_YELLOW
float: builtins.str = ANSIColors.BOLD_YELLOW
complex: builtins.str = ANSIColors.BOLD_YELLOW
bool: builtins.str = ANSIColors.BOLD_YELLOW

# others
type: str = ANSIColors.BOLD_MAGENTA
module: str = ANSIColors.CYAN
NoneType: str = ANSIColors.GREY
bytes: str = ANSIColors.BOLD_GREEN
str: str = ANSIColors.BOLD_GREEN
type: builtins.str = ANSIColors.BOLD_MAGENTA
module: builtins.str = ANSIColors.CYAN
NoneType: builtins.str = ANSIColors.GREY
bytes: builtins.str = ANSIColors.BOLD_GREEN
str: builtins.str = ANSIColors.BOLD_GREEN


@dataclass(frozen=True, kw_only=True)
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test__colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
import unittest.mock
import _colorize
from test.support import cpython_only, import_helper
from test.support.os_helper import EnvironmentVarGuard


Expand All @@ -22,6 +23,15 @@ def supports_virtual_terminal():
return contextlib.nullcontext()


class TestImportTime(unittest.TestCase):

@cpython_only
def test_lazy_import(self):
import_helper.ensure_lazy_imports(
"_colorize", {"re", "copy"}
)


class TestTheme(unittest.TestCase):

def test_attributes(self):
Expand Down
Loading