Skip to content

Commit

Permalink
Fixes for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Jan 23, 2020
1 parent 2bc7dbe commit 86bcf64
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 159 deletions.
5 changes: 3 additions & 2 deletions .pylintrc
Expand Up @@ -15,11 +15,12 @@ disable=
I,
fixme,
c-extension-no-member,
ungrouped-imports
ungrouped-imports,
useless-object-inheritance # Python 2

[FORMAT]
max-line-length: 100
good-names=ks,fd,_
good-names=ks,fd,_,x,y

[PARAMETER_DOCUMENTATION]
default-docstring-type=sphinx
Expand Down
4 changes: 2 additions & 2 deletions bin/colorchart.py
@@ -1,5 +1,5 @@
# encoding: utf-8
"""Utility to show X11 colors in 24-bit and down-converted to 256, 16, and 8 color The time to
"""Utility to show X11 colors in 24-bit and downconverted to 256, 16, and 8 color The time to
generate the table is displayed to give an indication of how long each algorithm takes compared to
the others."""
# std imports
Expand Down Expand Up @@ -30,7 +30,7 @@ def sort_colors():


def draw_chart(term):
"""Draw a chart of each X11 color represented as in 24-bit and as down-converted to 256, 16, and
"""Draw a chart of each X11 color represented as in 24-bit and as downconverted to 256, 16, and
8 color with the currently configured algorithm."""
sys.stdout.write(term.home)
width = term.width
Expand Down
8 changes: 4 additions & 4 deletions bin/progress_bar.py
Expand Up @@ -2,10 +2,10 @@
"""
Example application for the 'blessed' Terminal library for python.
This isn't a real progress bar, just a sample "animated prompt" of sorts that
demonstrates the separate move_x() and move_yx() capabilities, made mainly to
test the `hpa' compatibility for 'screen' terminal type which fails to provide
one, but blessed recognizes that it actually does, and provides a proxy.
This isn't a real progress bar, just a sample "animated prompt" of sorts that demonstrates the
separate move_x() and move_yx() capabilities, made mainly to test the `hpa' compatibility for
'screen' terminal type which fails to provide one, but blessed recognizes that it actually does, and
provides a proxy.
"""
from __future__ import print_function

Expand Down
18 changes: 9 additions & 9 deletions blessed/color.py
Expand Up @@ -21,9 +21,9 @@ def rgb_to_xyz(red, green, blue):
"""
Convert standard RGB color to XYZ color.
:arg red: RGB value of Red.
:arg green: RGB value of Green.
:arg blue: RGB value of Blue.
:arg int red: RGB value of Red.
:arg int green: RGB value of Green.
:arg int blue: RGB value of Blue.
:returns: Tuple (X, Y, Z) representing XYZ color
:rtype: tuple
Expand Down Expand Up @@ -51,9 +51,9 @@ def xyz_to_lab(x_val, y_val, z_val):
"""
Convert XYZ color to CIE-Lab color.
:arg x_val: XYZ value of X.
:arg y_val: XYZ value of Y.
:arg z_val: XYZ value of Z.
:arg float x_val: XYZ value of X.
:arg float y_val: XYZ value of Y.
:arg float z_val: XYZ value of Z.
:returns: Tuple (L, a, b) representing CIE-Lab color
:rtype: tuple
Expand Down Expand Up @@ -81,9 +81,9 @@ def rgb_to_lab(red, green, blue):
"""
Convert RGB color to CIE-Lab color.
:arg red: RGB value of Red.
:arg green: RGB value of Green.
:arg blue: RGB value of Blue.
:arg int red: RGB value of Red.
:arg int green: RGB value of Green.
:arg int blue: RGB value of Blue.
:returns: Tuple (L, a, b) representing CIE-Lab color
:rtype: tuple
Expand Down
4 changes: 4 additions & 0 deletions blessed/colorspace.py
@@ -1,4 +1,6 @@
"""
Color reference data.
References,
- https://github.com/freedesktop/xorg-rgb/blob/master/rgb.txt
Expand All @@ -24,6 +26,8 @@


class RGBColor(collections.namedtuple("RGBColor", ["red", "green", "blue"])):
"""Named tuple for an RGB color definition."""

def __str__(self):
return '#{0:02x}{1:02x}{2:02x}'.format(*self)

Expand Down
90 changes: 54 additions & 36 deletions blessed/formatters.py
Expand Up @@ -20,6 +20,7 @@ def _make_colors():
Return set of valid colors and their derivatives.
:rtype: set
:returns: Color names with prefixes
"""
colors = set()
# basic CGA foreground color, background, high intensity, and bold
Expand Down Expand Up @@ -58,18 +59,18 @@ class ParameterizingString(six.text_type):
u'\x1b[91mcolor #9\x1b(B\x1b[m'
"""

def __new__(cls, *args):
def __new__(cls, cap, normal=u'', name=u'<not specified>'):
# pylint: disable = missing-return-doc, missing-return-type-doc
"""
Class constructor accepting 3 positional arguments.
:arg cap: parameterized string suitable for curses.tparm()
:arg normal: terminating sequence for this capability (optional).
:arg name: name of this terminal capability (optional).
:arg str cap: parameterized string suitable for curses.tparm()
:arg str normal: terminating sequence for this capability (optional).
:arg str name: name of this terminal capability (optional).
"""
assert args and len(args) < 4, args
new = six.text_type.__new__(cls, args[0])
new._normal = args[1] if len(args) > 1 else u''
new._name = args[2] if len(args) > 2 else u'<not specified>'
new = six.text_type.__new__(cls, cap)
new._normal = normal
new._name = name
return new

def __call__(self, *args):
Expand All @@ -80,7 +81,10 @@ def __call__(self, *args):
``*args``, followed by the terminating sequence (self.normal) into
a :class:`FormattingString` capable of being called.
:raises TypeError: Mismatch between capability and arguments
:raises curses.error: :func:`curses.tparm` raised an exception
:rtype: :class:`FormattingString` or :class:`NullCallableString`
:returns: Callable string for given parameters
"""
try:
# Re-encode the cap, because tparm() takes a bytestring in Python
Expand Down Expand Up @@ -133,22 +137,23 @@ class ParameterizingProxyString(six.text_type):
u'\x1b[10G'
"""

def __new__(cls, *args):
def __new__(cls, fmt_pair, normal=u'', name=u'<not specified>'):
# pylint: disable = missing-return-doc, missing-return-type-doc
"""
Class constructor accepting 4 positional arguments.
:arg fmt: format string suitable for displaying terminal sequences.
:arg callable: receives __call__ arguments for formatting fmt.
:arg normal: terminating sequence for this capability (optional).
:arg name: name of this terminal capability (optional).
:arg tuple fmt_pair: Two element tuple containing:
- format string suitable for displaying terminal sequences
- callable suitable for receiving __call__ arguments for formatting string
:arg str normal: terminating sequence for this capability (optional).
:arg str name: name of this terminal capability (optional).
"""
assert args and len(args) < 4, args
assert isinstance(args[0], tuple), args[0]
assert callable(args[0][1]), args[0][1]
new = six.text_type.__new__(cls, args[0][0])
new._fmt_args = args[0][1]
new._normal = args[1] if len(args) > 1 else u''
new._name = args[2] if len(args) > 2 else u'<not specified>'
assert isinstance(fmt_pair, tuple), fmt_pair
assert callable(fmt_pair[1]), fmt_pair[1]
new = six.text_type.__new__(cls, fmt_pair[0])
new._fmt_args = fmt_pair[1]
new._normal = normal
new._name = name
return new

def __call__(self, *args):
Expand All @@ -161,10 +166,12 @@ def __call__(self, *args):
given capability.
:rtype: FormattingString
:returns: Callable string for given parameters
"""
return FormattingString(self.format(*self._fmt_args(*args)),
self._normal)


class FormattingString(six.text_type):
r"""
A Unicode string which doubles as a callable.
Expand All @@ -182,20 +189,26 @@ class FormattingString(six.text_type):
u'\x1b[94mBig Blue\x1b(B\x1b[m'
"""

def __new__(cls, *args):
def __new__(cls, sequence, normal=u''):
# pylint: disable = missing-return-doc, missing-return-type-doc
"""
Class constructor accepting 2 positional arguments.
:arg sequence: terminal attribute sequence.
:arg normal: terminating sequence for this attribute (optional).
:arg str sequence: terminal attribute sequence.
:arg str normal: terminating sequence for this attribute (optional).
"""
assert 1 <= len(args) <= 2, args
new = six.text_type.__new__(cls, args[0])
new._normal = args[1] if len(args) > 1 else u''
new = six.text_type.__new__(cls, sequence)
new._normal = normal
return new

def __call__(self, *args):
"""Return ``text`` joined by ``sequence`` and ``normal``."""
"""
Return ``text`` joined by ``sequence`` and ``normal``.
:raises TypeError: Not a string type
:rtype: str
:returns: Arguments wrapped in sequence and normal
"""
# Jim Allman brings us this convenience of allowing existing
# unicode strings to be joined as a call parameter to a formatting
# string result, allowing nestation:
Expand Down Expand Up @@ -224,7 +237,8 @@ class FormattingOtherString(six.text_type):
r"""
A Unicode string which doubles as a callable for another sequence when called.
This is used for the :meth:`~.Terminal.move_up`, ``down``, ``left``, and ``right()`` family of functions::
This is used for the :meth:`~.Terminal.move_up`, ``down``, ``left``, and ``right()``
family of functions::
>>> move_right = FormattingOtherString(term.cuf1, term.cuf)
>>> print(repr(move_right))
Expand All @@ -235,24 +249,25 @@ class FormattingOtherString(six.text_type):
u'\x1b[C'
"""

def __new__(cls, *args):
def __new__(cls, direct, target):
# pylint: disable = missing-return-doc, missing-return-type-doc
"""
Class constructor accepting 2 positional arguments.
:arg str direct: capability name for direct formatting, eg ``('x' + term.right)``.
:arg str callable: capability name for callable, eg ``('x' + term.right(99))``.
:arg str target: capability name for callable, eg ``('x' + term.right(99))``.
"""
assert 2 == len(args), args
new = six.text_type.__new__(cls, args[0])
new._callable = args[1]
new = six.text_type.__new__(cls, direct)
new._callable = target
return new

def __call__(self, *args):
"""Return ``text`` by ``callable``."""
"""Return ``text`` by ``target``."""
if args:
return self._callable(*args)
return self


class NullCallableString(six.text_type):
"""
A dummy callable Unicode alternative to :class:`FormattingString`.
Expand Down Expand Up @@ -343,6 +358,7 @@ def split_compound(compound):
:arg str compound: a string that may contain compounds, separated by
underline (``_``).
:rtype: list
:returns: List of formating string segments
"""
merged_segs = []
# These occur only as prefixes, so they can always be merged:
Expand Down Expand Up @@ -370,7 +386,7 @@ def resolve_capability(term, attr):
# b'\xff' is returned, this must be decoded to u'\xff'.
if not term.does_styling:
return u''
val = curses.tigetstr(term._sugar.get(attr, attr))
val = curses.tigetstr(term._sugar.get(attr, attr)) # pylint: disable=protected-access
return u'' if val is None else val.decode('latin1')


Expand All @@ -390,6 +406,7 @@ def resolve_color(term, color):
otherwise :class:`FormattingString`.
:rtype: :class:`NullCallableString` or :class:`FormattingString`
"""
# pylint: disable=protected-access
if term.number_of_colors == 0:
return NullCallableString()

Expand Down Expand Up @@ -467,7 +484,8 @@ def resolve_attribute(term, attr):
# and, for special terminals, such as 'screen', provide a Proxy
# ParameterizingString for attributes they do not claim to support,
# but actually do! (such as 'hpa' and 'vpa').
proxy = get_proxy_string(term, term._sugar.get(attr, attr))
proxy = get_proxy_string(term,
term._sugar.get(attr, attr)) # pylint: disable=protected-access
if proxy is not None:
return proxy

Expand Down

0 comments on commit 86bcf64

Please sign in to comment.