Skip to content

Commit 1894601

Browse files
MarkKoz64json
authored andcommitted
Add Serializable type annotation to command()
* Move _Number type alias to __init__.py
1 parent e2e6654 commit 1894601

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

algorithm_visualizer/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import atexit
22
import json
33
import os
4+
from typing import Union
45

56
from algorithm_visualizer import randomize as Randomize
67
from algorithm_visualizer.commander import Commander
@@ -11,6 +12,10 @@
1112
"Array1DTracer", "Array2DTracer", "ChartTracer", "LogTracer", "Tracer"
1213
)
1314

15+
# Types which are serializable by the default JSONEncoder
16+
_Serializable = Union[dict, list, str, int, float, bool, None]
17+
_Number = Union[int, float]
18+
1419

1520
@atexit.register
1621
def execute():

algorithm_visualizer/commander.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import string
22
from typing import Any, Dict, List, Optional
33

4-
from algorithm_visualizer import randomize
4+
from algorithm_visualizer import Randomize, _Serializable
55

66
_MAX_COMMANDS = 1000000
77
_MAX_OBJECTS = 100
88

99

1010
class Commander:
11-
_keyRandomizer = randomize.String(8, string.ascii_lowercase + string.digits)
11+
_keyRandomizer = Randomize.String(8, string.ascii_lowercase + string.digits)
1212
_objectCount = 0
1313
commands: List[Dict[str, Any]] = []
1414

@@ -18,7 +18,7 @@ def __init__(self, *args):
1818
self.command(self.__class__.__name__, *args)
1919

2020
@classmethod
21-
def _command(cls, key: Optional[str], method: str, *args):
21+
def _command(cls, key: Optional[str], method: str, *args: _Serializable):
2222
cmd = {
2323
"key": key,
2424
"method": method,

algorithm_visualizer/randomize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import abc
22
import random
33
import string
4-
from typing import List, NoReturn, Sequence, Union
4+
from typing import List, NoReturn, Sequence
55

6-
_Number = Union[float, int]
6+
from algorithm_visualizer import _Number
77

88

99
class Randomizer(metaclass=abc.ABCMeta):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy