Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate __ALL__, use __all__ instead #23

Merged
merged 3 commits into from Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/termcolor/__init__.py
@@ -1,3 +1,4 @@
"""ANSI color formatting for output in terminal."""
from __future__ import annotations

from termcolor.termcolor import ATTRIBUTES, COLORS, HIGHLIGHTS, RESET, colored, cprint
Expand Down
16 changes: 14 additions & 2 deletions src/termcolor/termcolor.py
Expand Up @@ -25,9 +25,21 @@
from __future__ import annotations

import os
import warnings
from typing import Any, Iterable

__ALL__ = ["colored", "cprint"]

def __getattr__(name: str) -> list[str]:
if name == "__ALL__":
warnings.warn(
"__ALL__ is deprecated and will be removed in termcolor 3. "
"Use __all__ instead.",
DeprecationWarning,
stacklevel=2,
)
return ["colored", "cprint"]
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")


ATTRIBUTES = dict(
list(
Expand Down Expand Up @@ -144,7 +156,7 @@ def cprint(


if __name__ == "__main__":
print("Current terminal type: %s" % os.getenv("TERM"))
print(f"Current terminal type: {os.getenv('TERM')}")
print("Test basic colors:")
cprint("Grey color", "grey")
cprint("Red color", "red")
Expand Down
10 changes: 8 additions & 2 deletions tests/test_termcolor.py
Expand Up @@ -5,7 +5,7 @@

import pytest

from termcolor import ATTRIBUTES, COLORS, HIGHLIGHTS, colored, cprint
from termcolor import ATTRIBUTES, COLORS, HIGHLIGHTS, colored, cprint, termcolor

ALL_COLORS = [*COLORS, None]
ALL_HIGHLIGHTS = [*HIGHLIGHTS, None]
Expand Down Expand Up @@ -119,9 +119,15 @@ def test_attrs(capsys: pytest.CaptureFixture[str], attr: str, expected: str) ->
"",
],
)
def test_env_var(
def test_environment_variables(
monkeypatch: pytest.MonkeyPatch, test_env_var: str, test_value: str
) -> None:
"""Assert nothing applied when this env var set, regardless of value."""
monkeypatch.setenv(test_env_var, test_value)
assert colored("text", color="red") == "text"


def test_all_deprecation() -> None:
"""Assert that __ALL__ is deprecated (use __all__ instead)"""
with pytest.deprecated_call():
assert termcolor.__ALL__