8000 A more accurate `termcolor.colored` fallback by Avasam · Pull Request #9435 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

A more accurate termcolor.colored fallback #9435

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

Merged
merged 2 commits into from
Dec 31, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import subprocess
import sys
from pathlib import Path
from typing import Iterable

try:
from termcolor import colored
except ImportError:

def colored(text: str, color: str = "") -> str: # type: ignore[misc]
def colored(text: str, color: str | None = None, on_color: str | None = None, attrs: Iterable[str] | None = None) -> str:
return text


Expand Down
18 changes: 9 additions & 9 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@
from collections.abc import Mapping
from functools import cache
from pathlib import Path
from typing import NamedTuple
from typing import Iterable, NamedTuple
from typing_extensions import Annotated

import pathspec # type: ignore[import]
import tomli
from packaging.requirements import Requirement

try:
from termcolor import colored as colored
except ImportError:

def colored(text: str, color: str | None = None, on_color: str | None = None, attrs: Iterable[str] | None = None) -> str:
return text


# Used to install system-wide packages for different OS types:
METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"}

Expand All @@ -25,14 +33,6 @@ def strip_comments(text: str) -> str:
return text.split("#")[0].strip()


try:
from termcolor import colored as colored
except ImportError:

def colored(s: str, _: str) -> str: # type: ignore[misc]
return s


def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None:
error_split = error.split("\n")
old, new = fix_path
Expand Down
0