Skip to content

Commit a322af5

Browse files
committed
Accept suggestions from new toolchain
1 parent 0936e78 commit a322af5

15 files changed

+46
-37
lines changed

nc/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@
6868
# (122, 110, 250) is closest to Slate blue 1 = 131 111 255
6969
# (56, 218, 180) is closest to Turquoise = 64 224 208
7070
"""
71-
from . import colors as _colors
72-
from . import color as _color
73-
from functools import cached_property
74-
from typing import Iterator
7571
import sys
72+
from functools import cached_property
73+
from collections.abc import Iterator
74+
75+
from . import color as _color
76+
from . import colors as _colors
7677

7778
_DEFAULT_PALETTES = "wikipedia", "x11", "juce"
7879

nc/__main__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from nc import Color
2-
from nc import demo
3-
from nc import terminal
41
import argparse
5-
import nc
62
import sys
73

4+
import nc
5+
from nc import Color, demo, terminal
6+
87
DEFAULT_COMMAND = "all"
98

109

@@ -37,10 +36,10 @@ def main(sys_args, color_count=None):
3736
context = terminal.Context(color_count)
3837
first = True
3938
for name, color in colors:
40-
assert type(name) is str
39+
assert isinstance(name, str)
4140
assert "Color" in type(color).__name__, type(color).__name__
4241
background = nc.black if sum(color) >= 0x180 else nc.white
43-
msg = "%s%s: %s" % ("" if first else "\n", name, tuple(color))
42+
msg = "{}{}: {}".format("" if first else "\n", name, tuple(color))
4443
first = False
4544
if context:
4645
with context(color, background, print):

nc/color.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from functools import cached_property
2-
from typing import Tuple
31
import collections
42
import colorsys
53
import math
64
import numbers
75
import typing as t
6+
from functools import cached_property
87

98
from typing_extensions import Protocol
109

@@ -50,7 +49,7 @@ def closest(self) -> "Color":
5049

5150
def distance2(self, other) -> int:
5251
"""Return the square of the distance between this and another color"""
53-
d = (i - j for i, j in zip(self, other))
52+
d = (i - j for i, j in zip(self, other, strict=False))
5453
return sum(i * i for i in d)
5554

5655
def distance(self, other) -> float:

nc/colors.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from . import color
2-
from functools import cached_property
31
import importlib
42
import re
53
import string
64
import typing as t
5+
from functools import cached_property
6+
7+
from . import color
78

89
_ALLOWED = set(string.ascii_letters + string.digits)
910

@@ -94,7 +95,7 @@ def __getattr__(self, name: str) -> color.Color:
9495
try:
9596
return self[name]
9697
except KeyError:
97-
raise AttributeError(name)
98+
raise AttributeError(name) from None
9899

99100
def __setattr__(self, name, value):
100101
if name.startswith("_"):
@@ -174,7 +175,7 @@ def _canonical_name(self, name) -> str:
174175
return "".join(i for i in name if i in _ALLOWED)
175176

176177
@cached_property
177-
def _colors(self) -> t.Dict[str, Color]:
178+
def _colors(self) -> t.Dict[str, color.Color]:
178179
return {k: self.Color(*v) for k, v in self._name_to_rgb.items()}
179180

180181
@cached_property

nc/demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from . import terminal
21
import subprocess
32
import sys
43
import time
54

5+
from . import terminal
6+
67
DEFAULT_COLUMNS = 64
78
DEMO_CHAR = "•"
89

nc/terminal.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from .colors import Colors
21
import contextlib
32
import functools
43
import subprocess
54

5+
from .colors import Colors
6+
67
TERMINAL_ENVIRONMENT_VAR = "_NC_TERMINAL_COLOR_COUNT"
78
SIZES = 256, 16, 8
89

@@ -11,7 +12,7 @@ def context(fg=None, bg=None, print=print, count=None):
1112
return Context(count)(fg, bg, print)
1213

1314

14-
@functools.lru_cache()
15+
@functools.lru_cache
1516
def color_count():
1617
cmd = "tput", "colors"
1718
try:
@@ -65,4 +66,4 @@ def color_codes(color, coder):
6566
yield
6667

6768

68-
Context = functools.lru_cache()(_Context)
69+
Context = functools.lru_cache(_Context)

test/nc/print_mocker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from unittest import mock
21
import contextlib
32
import io
3+
from unittest import mock
44

55

66
@contextlib.contextmanager

test/nc/test_color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from nc import COLORS
2-
from nc import Color
31
import unittest
42

3+
from nc import COLORS, Color
4+
55

66
class ColorTest(unittest.TestCase):
77
def test_empty(self):

test/nc/test_colors.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from nc import COLORS
2-
from nc import Color
3-
from nc import Colors
4-
from nc.palette import juce
51
import unittest
62

3+
from nc import COLORS, Color, Colors
4+
from nc.palette import juce
5+
76

87
class ColorsTest(unittest.TestCase):
98
def test_colors(self):

test/nc/test_custom_colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import nc
21
import unittest
32

3+
import nc
4+
45

56
class CustomColorsTest(unittest.TestCase):
67
def test_dict_module(self):

0 commit comments

Comments
 (0)