Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 4e12fa4

Browse files
4.0.0 refactoring - finished the tests
1 parent 67e73af commit 4e12fa4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+973
-61
lines changed

multibar/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
from .impl import *
33

44
__all__ = (
5-
"CalculationServiceAware",
5+
"AbstractCalculationService",
66
"ProgressbarClientAware",
77
"ContractAware",
88
"ContractCheck",
99
"ContractManagerAware",
1010
"HookSignatureType",
1111
"HooksAware",
1212
"ProgressbarAware",
13-
"SectorAware",
13+
"AbstractSector",
1414
"SignatureSegmentProtocol",
1515
"ProgressbarSignatureProtocol",
1616
"ProgressbarWriterAware",
1717
"ProgressbarCalculationService",
1818
"ProgressbarClient",
1919
"ContractManager",
2020
"WriteProgressContract",
21+
"WRITE_PROGRESS_CONTRACT",
2122
"Hooks",
2223
"WRITER_HOOKS",
2324
"Progressbar",
2425
"Sector",
25-
"Signature",
26+
"SimpleSignature",
2627
"SignatureSegment",
2728
"ProgressbarWriter",
2829
)

multibar/api/clients.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from . import hooks as hooks_
1010

1111
if typing.TYPE_CHECKING:
12-
from multibar.api import progressbars, sectors
12+
from multibar.api import progressbars, sectors, writers
1313

1414

1515
class ProgressbarClientAware(abc.ABC):
@@ -20,7 +20,7 @@ def get_progress(
2020
start_value: int,
2121
end_value: int,
2222
/,
23-
) -> typing.Optional[progressbars.ProgressbarAware[sectors.AbstractSector]]:
23+
) -> progressbars.ProgressbarAware[sectors.AbstractSector]:
2424
...
2525

2626
@abc.abstractmethod
@@ -32,7 +32,7 @@ def get_progress(
3232
/,
3333
*,
3434
length: int,
35-
) -> typing.Optional[progressbars.ProgressbarAware[sectors.AbstractSector]]:
35+
) -> progressbars.ProgressbarAware[sectors.AbstractSector]:
3636
...
3737

3838
@abc.abstractmethod
@@ -43,7 +43,7 @@ def get_progress(
4343
/,
4444
*,
4545
length: int = 20,
46-
) -> typing.Optional[progressbars.ProgressbarAware[sectors.AbstractSector]]:
46+
) -> progressbars.ProgressbarAware[sectors.AbstractSector]:
4747
...
4848

4949
@abc.abstractmethod
@@ -63,3 +63,8 @@ def hooks(self) -> hooks_.HooksAware:
6363
@abc.abstractmethod
6464
def contract_manager(self) -> contracts.ContractManagerAware:
6565
...
66+
67+
@property
68+
@abc.abstractmethod
69+
def writer(self) -> writers.ProgressbarWriterAware[sectors.AbstractSector]:
70+
...

multibar/api/contracts.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def subscribe(self, contract: ContractAware, /) -> None:
8181
def terminate(self, contract: ContractAware, /) -> None:
8282
...
8383

84+
@abc.abstractmethod
85+
def terminate_all(self) -> None:
86+
...
87+
8488
@abc.abstractmethod
8589
def set_raise_errors(self, value: bool, /) -> None:
8690
...
@@ -89,3 +93,8 @@ def set_raise_errors(self, value: bool, /) -> None:
8993
@abc.abstractmethod
9094
def contracts(self) -> list[ContractAware]:
9195
...
96+
97+
@property
98+
@abc.abstractmethod
99+
def raise_errors(self) -> bool:
100+
...

multibar/api/hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class HooksAware(abc.ABC):
2020
__slots__ = ()
2121

2222
@abc.abstractmethod
23-
def __bool__(self) -> bool:
23+
def __len__(self) -> int:
2424
...
2525

2626
@abc.abstractmethod

multibar/api/progressbars.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,27 @@
1111

1212

1313
class ProgressbarAware(abc.ABC, typing.Generic[SectorT]):
14+
@typing.overload
15+
@abc.abstractmethod
16+
def __getitem__(self, item: slice) -> typing.Sequence[SectorT]:
17+
...
18+
19+
@typing.overload
20+
@abc.abstractmethod
21+
def __getitem__(self, item: int) -> SectorT:
22+
...
23+
24+
@abc.abstractmethod
25+
def __getitem__(self, item: typing.Any) -> typing.Any:
26+
...
27+
1428
@abc.abstractmethod
1529
def add_sector(self, sector: SectorT, /) -> ProgressbarAware[SectorT]:
1630
...
1731

1832
@abc.abstractmethod
1933
def replace_visual(
20-
self, sector_pos: int, new_visual: typing.Union[str, bytes], /
34+
self, sector_pos: int, new_visual: str, /
2135
) -> ProgressbarAware[SectorT]:
2236
...
2337

multibar/api/sectors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class AbstractSector(abc.ABC):
1515
__slots__ = ("_name", "_is_filled", "_position")
1616

17-
def __init__(self, name: typing.Union[str, bytes], is_filled: bool, position: int) -> None:
17+
def __init__(self, name: str, is_filled: bool, position: int) -> None:
1818
self._name = name
1919
self._is_filled = is_filled
2020
self._position = position
@@ -23,13 +23,13 @@ def __init__(self, name: typing.Union[str, bytes], is_filled: bool, position: in
2323
def add_to_progressbar(self: SelfT, progressbar: progressbars.ProgressbarAware[SelfT], /) -> SelfT:
2424
...
2525

26-
@property
2726
@abc.abstractmethod
28-
def name(self) -> typing.Union[str, bytes]:
27+
def change_name(self, value: str, /) -> AbstractSector:
2928
...
3029

30+
@property
3131
@abc.abstractmethod
32-
def change_name(self, value: typing.Union[str, bytes], /) -> AbstractSector:
32+
def name(self) -> str:
3333
...
3434

3535
@property

multibar/api/signatures.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
@typing.runtime_checkable
1010
class SignatureSegmentProtocol(typing.Protocol):
1111
@property
12-
def on_filled(self) -> typing.Union[str, bytes]:
13-
# TODO: mypy has some problems with typing.AnyStr
12+
def on_filled(self) -> str:
1413
raise NotImplementedError
1514

1615
@property
17-
def on_unfilled(self) -> typing.Union[str, bytes]:
16+
def on_unfilled(self) -> str:
1817
raise NotImplementedError
1918

2019

multibar/errors.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import typing
44

55
if typing.TYPE_CHECKING:
6-
from .api import contracts
6+
from multibar.api import contracts
77

88

99
class MultibarError(Exception):
@@ -14,17 +14,21 @@ class ContractError(MultibarError):
1414
pass
1515

1616

17-
class UnsignedContractError(ContractError):
18-
pass
19-
20-
21-
class TerminatedContractError(ContractError):
17+
class ContractResponseError(ContractError):
2218
__slots__ = ("contract_check",)
2319

24-
def __init__(self, *, check: contracts.ContractCheck) -> None:
20+
def __init__(self, check: contracts.ContractCheck, /) -> None:
2521
self.contract_check = check
2622
super().__init__(self._process_check())
2723

2824
def _process_check(self) -> str:
2925
messages = self.contract_check.errors + self.contract_check.warnings
3026
return " & ".join(messages)
27+
28+
29+
class UnsignedContractError(ContractError):
30+
pass
31+
32+
33+
class TerminatedContractError(ContractResponseError):
34+
pass

multibar/impl/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
"ProgressbarClient",
1313
"ContractManager",
1414
"WriteProgressContract",
15+
"WRITE_PROGRESS_CONTRACT",
1516
"Hooks",
1617
"WRITER_HOOKS",
1718
"Progressbar",
1819
"Sector",
19-
"Signature",
20+
"SimpleSignature",
2021
"SignatureSegment",
2122
"ProgressbarWriter",
2223
)

multibar/impl/clients.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_progress(
5151
/,
5252
*,
5353
length: int = 20,
54-
) -> typing.Optional[abc_progressbars.ProgressbarAware[abc_sectors.AbstractSector]]:
54+
) -> abc_progressbars.ProgressbarAware[abc_sectors.AbstractSector]:
5555
writer = self._writer
5656
call_metadata: progress_types.ProgressMetadataType = {
5757
"calculation_service_cls": writer.calculation_cls,
@@ -86,3 +86,7 @@ def hooks(self) -> abc_hooks.HooksAware:
8686
@property
8787
def contract_manager(self) -> abc_contracts.ContractManagerAware:
8888
return self._contract_manager
89+
90+
@property
91+
def writer(self) -> abc_writers.ProgressbarWriterAware[abc_sectors.AbstractSector]:
92+
return self._writer

0 commit comments

Comments
 (0)