Skip to content

Commit 96f632b

Browse files
committed
chore: fix ABC of Formatter and add annotations.
Formatter base class requires .stream, so just force it. I need to go in and just collapse that ontology, the annotations are layer violations are painful AF due to the history of how that evolved and tooling back then being insufficient to do this sort of refactor safely. This will be addressed via pkgcore#113. Signed-off-by: Brian Harring <ferringb@gmail.com>
1 parent 2168029 commit 96f632b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/snakeoil/cli/tool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
class Tool:
1818
"""Abstraction for commandline tools."""
1919

20+
out: formatters.Formatter
21+
err: formatters.Formatter
22+
2023
def __init__(self, parser, outfile=None, errfile=None):
2124
"""Initialize the utility to run.
2225

src/snakeoil/formatters.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Classes wrapping a file-like object to do fancy output on it."""
22

3+
import abc
34
import errno
45
import io
56
import locale
@@ -32,7 +33,7 @@ class StreamClosed(KeyboardInterrupt):
3233
# pylint: disable=C0103
3334

3435

35-
class Formatter:
36+
class Formatter(abc.ABC):
3637
"""Abstract formatter base class.
3738
3839
The types of most of the instance attributes is undefined (depends
@@ -46,10 +47,12 @@ class Formatter:
4647
(defaults to on).
4748
"""
4849

49-
def __init__(self):
50+
def __init__(self, stream: typing.IO):
5051
self.autoline = True
5152
self.wrap = False
53+
self.stream = stream
5254

55+
@abc.abstractmethod
5356
def write(
5457
self,
5558
*args: typing.Union[None, str, typing.Callable[["Formatter"], None]],
@@ -146,7 +149,7 @@ def __init__(
146149
:param width: maximum line width (defaults to 79).
147150
:param encoding: encoding unicode strings are converted to.
148151
"""
149-
super().__init__()
152+
super().__init__(stream)
150153
# We used to require a TextIOWrapper on py3. We still accept
151154
# one, guess the encoding from it and grab its underlying
152155
# bytestream.

0 commit comments

Comments
 (0)